aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_arena/src/lib.rs101
-rw-r--r--crates/ra_arena/src/map.rs32
-rw-r--r--crates/ra_hir_def/src/adt.rs18
-rw-r--r--crates/ra_hir_def/src/body.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs6
-rw-r--r--crates/ra_hir_def/src/body/scope.rs8
-rw-r--r--crates/ra_hir_def/src/expr.rs17
-rw-r--r--crates/ra_hir_def/src/generics.rs2
-rw-r--r--crates/ra_hir_def/src/lib.rs18
-rw-r--r--crates/ra_hir_def/src/nameres.rs4
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs88
-rw-r--r--crates/ra_hir_def/src/nameres/tests/mod_resolution.rs8
-rw-r--r--crates/ra_hir_def/src/trace.rs22
-rw-r--r--crates/ra_hir_expand/src/ast_id_map.rs8
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs14
-rw-r--r--crates/ra_project_model/src/sysroot.rs8
17 files changed, 175 insertions, 185 deletions
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs
index fc0f7c12f..ea98d5444 100644
--- a/crates/ra_arena/src/lib.rs
+++ b/crates/ra_arena/src/lib.rs
@@ -2,6 +2,7 @@
2 2
3use std::{ 3use std::{
4 fmt, 4 fmt,
5 hash::{Hash, Hasher},
5 iter::FromIterator, 6 iter::FromIterator,
6 marker::PhantomData, 7 marker::PhantomData,
7 ops::{Index, IndexMut}, 8 ops::{Index, IndexMut},
@@ -36,86 +37,110 @@ impl fmt::Display for RawId {
36 } 37 }
37} 38}
38 39
39#[derive(Clone, PartialEq, Eq)] 40pub struct Idx<T> {
40pub struct Arena<ID, T> { 41 raw: RawId,
41 data: Vec<T>, 42 _ty: PhantomData<fn() -> T>,
42 _ty: PhantomData<ID>,
43} 43}
44 44
45impl<ID: ArenaId, T: fmt::Debug> fmt::Debug for Arena<ID, T> { 45impl<T> Clone for Idx<T> {
46 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 46 fn clone(&self) -> Self {
47 fmt.debug_struct("Arena").field("len", &self.len()).field("data", &self.data).finish() 47 *self
48 } 48 }
49} 49}
50impl<T> Copy for Idx<T> {}
50 51
51#[macro_export] 52impl<T> PartialEq for Idx<T> {
52macro_rules! impl_arena_id { 53 fn eq(&self, other: &Idx<T>) -> bool {
53 ($name:ident) => { 54 self.raw == other.raw
54 impl $crate::ArenaId for $name { 55 }
55 fn from_raw(raw: $crate::RawId) -> Self { 56}
56 $name(raw) 57impl<T> Eq for Idx<T> {}
57 } 58
58 fn into_raw(self) -> $crate::RawId { 59impl<T> Hash for Idx<T> {
59 self.0 60 fn hash<H: Hasher>(&self, state: &mut H) {
60 } 61 self.raw.hash(state)
62 }
63}
64
65impl<T> fmt::Debug for Idx<T> {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 let mut type_name = std::any::type_name::<T>();
68 if let Some(idx) = type_name.rfind(':') {
69 type_name = &type_name[idx + 1..]
61 } 70 }
62 }; 71 write!(f, "Idx::<{}>({})", type_name, self.raw)
72 }
63} 73}
64 74
65pub trait ArenaId { 75impl<T> Idx<T> {
66 fn from_raw(raw: RawId) -> Self; 76 pub fn from_raw(raw: RawId) -> Self {
67 fn into_raw(self) -> RawId; 77 Idx { raw, _ty: PhantomData }
78 }
79 pub fn into_raw(self) -> RawId {
80 self.raw
81 }
82}
83
84#[derive(Clone, PartialEq, Eq)]
85pub struct Arena<T> {
86 data: Vec<T>,
68} 87}
69 88
70impl<ID, T> Arena<ID, T> { 89impl<T: fmt::Debug> fmt::Debug for Arena<T> {
71 pub const fn new() -> Arena<ID, T> { 90 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
72 Arena { data: Vec::new(), _ty: PhantomData } 91 fmt.debug_struct("Arena").field("len", &self.len()).field("data", &self.data).finish()
73 } 92 }
74} 93}
75 94
76impl<ID: ArenaId, T> Arena<ID, T> { 95impl<T> Arena<T> {
96 pub const fn new() -> Arena<T> {
97 Arena { data: Vec::new() }
98 }
99
77 pub fn len(&self) -> usize { 100 pub fn len(&self) -> usize {
78 self.data.len() 101 self.data.len()
79 } 102 }
80 pub fn is_empty(&self) -> bool { 103 pub fn is_empty(&self) -> bool {
81 self.data.is_empty() 104 self.data.is_empty()
82 } 105 }
83 pub fn alloc(&mut self, value: T) -> ID { 106 pub fn alloc(&mut self, value: T) -> Idx<T> {
84 let id = RawId(self.data.len() as u32); 107 let id = RawId(self.data.len() as u32);
85 self.data.push(value); 108 self.data.push(value);
86 ID::from_raw(id) 109 Idx::from_raw(id)
87 } 110 }
88 pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> + ExactSizeIterator + DoubleEndedIterator { 111 pub fn iter(
89 self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) 112 &self,
113 ) -> impl Iterator<Item = (Idx<T>, &T)> + ExactSizeIterator + DoubleEndedIterator {
114 self.data.iter().enumerate().map(|(idx, value)| (Idx::from_raw(RawId(idx as u32)), value))
90 } 115 }
91} 116}
92 117
93impl<ID: ArenaId, T> Default for Arena<ID, T> { 118impl<T> Default for Arena<T> {
94 fn default() -> Arena<ID, T> { 119 fn default() -> Arena<T> {
95 Arena { data: Vec::new(), _ty: PhantomData } 120 Arena { data: Vec::new() }
96 } 121 }
97} 122}
98 123
99impl<ID: ArenaId, T> Index<ID> for Arena<ID, T> { 124impl<T> Index<Idx<T>> for Arena<T> {
100 type Output = T; 125 type Output = T;
101 fn index(&self, idx: ID) -> &T { 126 fn index(&self, idx: Idx<T>) -> &T {
102 let idx = idx.into_raw().0 as usize; 127 let idx = idx.into_raw().0 as usize;
103 &self.data[idx] 128 &self.data[idx]
104 } 129 }
105} 130}
106 131
107impl<ID: ArenaId, T> IndexMut<ID> for Arena<ID, T> { 132impl<T> IndexMut<Idx<T>> for Arena<T> {
108 fn index_mut(&mut self, idx: ID) -> &mut T { 133 fn index_mut(&mut self, idx: Idx<T>) -> &mut T {
109 let idx = idx.into_raw().0 as usize; 134 let idx = idx.into_raw().0 as usize;
110 &mut self.data[idx] 135 &mut self.data[idx]
111 } 136 }
112} 137}
113 138
114impl<ID: ArenaId, T> FromIterator<T> for Arena<ID, T> { 139impl<T> FromIterator<T> for Arena<T> {
115 fn from_iter<I>(iter: I) -> Self 140 fn from_iter<I>(iter: I) -> Self
116 where 141 where
117 I: IntoIterator<Item = T>, 142 I: IntoIterator<Item = T>,
118 { 143 {
119 Arena { data: Vec::from_iter(iter), _ty: PhantomData } 144 Arena { data: Vec::from_iter(iter) }
120 } 145 }
121} 146}
diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs
index b73d4e365..5e764113d 100644
--- a/crates/ra_arena/src/map.rs
+++ b/crates/ra_arena/src/map.rs
@@ -2,17 +2,17 @@
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4 4
5use super::ArenaId; 5use crate::Idx;
6 6
7/// A map from arena IDs to some other type. Space requirement is O(highest ID). 7/// A map from arena IDs to some other type. Space requirement is O(highest ID).
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] 8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct ArenaMap<ID, T> { 9pub struct ArenaMap<ID, V> {
10 v: Vec<Option<T>>, 10 v: Vec<Option<V>>,
11 _ty: PhantomData<ID>, 11 _ty: PhantomData<ID>,
12} 12}
13 13
14impl<ID: ArenaId, T> ArenaMap<ID, T> { 14impl<T, V> ArenaMap<Idx<T>, V> {
15 pub fn insert(&mut self, id: ID, t: T) { 15 pub fn insert(&mut self, id: Idx<T>, t: V) {
16 let idx = Self::to_idx(id); 16 let idx = Self::to_idx(id);
17 if self.v.capacity() <= idx { 17 if self.v.capacity() <= idx {
18 self.v.reserve(idx + 1 - self.v.capacity()); 18 self.v.reserve(idx + 1 - self.v.capacity());
@@ -25,43 +25,43 @@ impl<ID: ArenaId, T> ArenaMap<ID, T> {
25 self.v[idx] = Some(t); 25 self.v[idx] = Some(t);
26 } 26 }
27 27
28 pub fn get(&self, id: ID) -> Option<&T> { 28 pub fn get(&self, id: Idx<T>) -> Option<&V> {
29 self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref()) 29 self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref())
30 } 30 }
31 31
32 pub fn get_mut(&mut self, id: ID) -> Option<&mut T> { 32 pub fn get_mut(&mut self, id: Idx<T>) -> Option<&mut V> {
33 self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut()) 33 self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut())
34 } 34 }
35 35
36 pub fn values(&self) -> impl Iterator<Item = &T> { 36 pub fn values(&self) -> impl Iterator<Item = &V> {
37 self.v.iter().filter_map(|o| o.as_ref()) 37 self.v.iter().filter_map(|o| o.as_ref())
38 } 38 }
39 39
40 pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T> { 40 pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V> {
41 self.v.iter_mut().filter_map(|o| o.as_mut()) 41 self.v.iter_mut().filter_map(|o| o.as_mut())
42 } 42 }
43 43
44 pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> { 44 pub fn iter(&self) -> impl Iterator<Item = (Idx<T>, &V)> {
45 self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?))) 45 self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?)))
46 } 46 }
47 47
48 fn to_idx(id: ID) -> usize { 48 fn to_idx(id: Idx<T>) -> usize {
49 u32::from(id.into_raw()) as usize 49 u32::from(id.into_raw()) as usize
50 } 50 }
51 51
52 fn from_idx(idx: usize) -> ID { 52 fn from_idx(idx: usize) -> Idx<T> {
53 ID::from_raw((idx as u32).into()) 53 Idx::from_raw((idx as u32).into())
54 } 54 }
55} 55}
56 56
57impl<ID: ArenaId, T> std::ops::Index<ID> for ArenaMap<ID, T> { 57impl<T, V> std::ops::Index<Idx<V>> for ArenaMap<Idx<V>, T> {
58 type Output = T; 58 type Output = T;
59 fn index(&self, id: ID) -> &T { 59 fn index(&self, id: Idx<V>) -> &T {
60 self.v[Self::to_idx(id)].as_ref().unwrap() 60 self.v[Self::to_idx(id)].as_ref().unwrap()
61 } 61 }
62} 62}
63 63
64impl<ID, T> Default for ArenaMap<ID, T> { 64impl<T, V> Default for ArenaMap<Idx<V>, T> {
65 fn default() -> Self { 65 fn default() -> Self {
66 ArenaMap { v: Vec::new(), _ty: PhantomData } 66 ArenaMap { v: Vec::new(), _ty: PhantomData }
67 } 67 }
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index d55c49938..de07fc952 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -27,7 +27,7 @@ pub struct StructData {
27#[derive(Debug, Clone, PartialEq, Eq)] 27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct EnumData { 28pub struct EnumData {
29 pub name: Name, 29 pub name: Name,
30 pub variants: Arena<LocalEnumVariantId, EnumVariantData>, 30 pub variants: Arena<EnumVariantData>,
31} 31}
32 32
33#[derive(Debug, Clone, PartialEq, Eq)] 33#[derive(Debug, Clone, PartialEq, Eq)]
@@ -38,8 +38,8 @@ pub struct EnumVariantData {
38 38
39#[derive(Debug, Clone, PartialEq, Eq)] 39#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum VariantData { 40pub enum VariantData {
41 Record(Arena<LocalStructFieldId, StructFieldData>), 41 Record(Arena<StructFieldData>),
42 Tuple(Arena<LocalStructFieldId, StructFieldData>), 42 Tuple(Arena<StructFieldData>),
43 Unit, 43 Unit,
44} 44}
45 45
@@ -104,7 +104,7 @@ impl HasChildSource for EnumId {
104 104
105fn lower_enum( 105fn lower_enum(
106 db: &dyn DefDatabase, 106 db: &dyn DefDatabase,
107 trace: &mut Trace<LocalEnumVariantId, EnumVariantData, ast::EnumVariant>, 107 trace: &mut Trace<EnumVariantData, ast::EnumVariant>,
108 ast: &InFile<ast::EnumDef>, 108 ast: &InFile<ast::EnumDef>,
109) { 109) {
110 for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) { 110 for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) {
@@ -128,8 +128,8 @@ impl VariantData {
128 } 128 }
129 } 129 }
130 130
131 pub fn fields(&self) -> &Arena<LocalStructFieldId, StructFieldData> { 131 pub fn fields(&self) -> &Arena<StructFieldData> {
132 const EMPTY: &Arena<LocalStructFieldId, StructFieldData> = &Arena::new(); 132 const EMPTY: &Arena<StructFieldData> = &Arena::new();
133 match &self { 133 match &self {
134 VariantData::Record(fields) | VariantData::Tuple(fields) => fields, 134 VariantData::Record(fields) | VariantData::Tuple(fields) => fields,
135 _ => EMPTY, 135 _ => EMPTY,
@@ -183,11 +183,7 @@ pub enum StructKind {
183 183
184fn lower_struct( 184fn lower_struct(
185 db: &dyn DefDatabase, 185 db: &dyn DefDatabase,
186 trace: &mut Trace< 186 trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>,
187 LocalStructFieldId,
188 StructFieldData,
189 Either<ast::TupleFieldDef, ast::RecordFieldDef>,
190 >,
191 ast: &InFile<ast::StructKind>, 187 ast: &InFile<ast::StructKind>,
192) -> StructKind { 188) -> StructKind {
193 match &ast.value { 189 match &ast.value {
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 34561ee73..27a297e8b 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -121,8 +121,8 @@ pub(crate) struct Mark {
121/// The body of an item (function, const etc.). 121/// The body of an item (function, const etc.).
122#[derive(Debug, Eq, PartialEq)] 122#[derive(Debug, Eq, PartialEq)]
123pub struct Body { 123pub struct Body {
124 pub exprs: Arena<ExprId, Expr>, 124 pub exprs: Arena<Expr>,
125 pub pats: Arena<PatId, Pat>, 125 pub pats: Arena<Pat>,
126 /// The patterns for the function's parameters. While the parameter types are 126 /// The patterns for the function's parameters. While the parameter types are
127 /// part of the function signature, the patterns are not (they don't change 127 /// part of the function signature, the patterns are not (they don't change
128 /// the external type of the function). 128 /// the external type of the function).
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 6238de606..e8c58ed32 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -24,8 +24,8 @@ use crate::{
24 builtin_type::{BuiltinFloat, BuiltinInt}, 24 builtin_type::{BuiltinFloat, BuiltinInt},
25 db::DefDatabase, 25 db::DefDatabase,
26 expr::{ 26 expr::{
27 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, 27 dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal,
28 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, 28 LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
29 }, 29 },
30 item_scope::BuiltinShadowMode, 30 item_scope::BuiltinShadowMode,
31 path::GenericArgs, 31 path::GenericArgs,
@@ -51,7 +51,7 @@ pub(super) fn lower(
51 exprs: Arena::default(), 51 exprs: Arena::default(),
52 pats: Arena::default(), 52 pats: Arena::default(),
53 params: Vec::new(), 53 params: Vec::new(),
54 body_expr: ExprId::dummy(), 54 body_expr: dummy_expr_id(),
55 item_scope: Default::default(), 55 item_scope: Default::default(),
56 }, 56 },
57 } 57 }
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index 7c3db8869..4d489f692 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -2,7 +2,7 @@
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_expand::name::Name; 4use hir_expand::name::Name;
5use ra_arena::{impl_arena_id, Arena, RawId}; 5use ra_arena::{Arena, Idx};
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7 7
8use crate::{ 8use crate::{
@@ -12,13 +12,11 @@ use crate::{
12 DefWithBodyId, 12 DefWithBodyId,
13}; 13};
14 14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 15pub type ScopeId = Idx<ScopeData>;
16pub struct ScopeId(RawId);
17impl_arena_id!(ScopeId);
18 16
19#[derive(Debug, PartialEq, Eq)] 17#[derive(Debug, PartialEq, Eq)]
20pub struct ExprScopes { 18pub struct ExprScopes {
21 scopes: Arena<ScopeId, ScopeData>, 19 scopes: Arena<ScopeData>,
22 scope_by_expr: FxHashMap<ExprId, ScopeId>, 20 scope_by_expr: FxHashMap<ExprId, ScopeId>,
23} 21}
24 22
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs
index 66d004717..197bbe9bd 100644
--- a/crates/ra_hir_def/src/expr.rs
+++ b/crates/ra_hir_def/src/expr.rs
@@ -13,7 +13,7 @@
13//! See also a neighboring `body` module. 13//! See also a neighboring `body` module.
14 14
15use hir_expand::name::Name; 15use hir_expand::name::Name;
16use ra_arena::{impl_arena_id, RawId}; 16use ra_arena::{Idx, RawId};
17use ra_syntax::ast::RangeOp; 17use ra_syntax::ast::RangeOp;
18 18
19use crate::{ 19use crate::{
@@ -22,19 +22,12 @@ use crate::{
22 type_ref::{Mutability, TypeRef}, 22 type_ref::{Mutability, TypeRef},
23}; 23};
24 24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 25pub type ExprId = Idx<Expr>;
26pub struct ExprId(RawId); 26pub(crate) fn dummy_expr_id() -> ExprId {
27impl_arena_id!(ExprId); 27 ExprId::from_raw(RawId::from(!0))
28
29impl ExprId {
30 pub fn dummy() -> ExprId {
31 ExprId((!0).into())
32 }
33} 28}
34 29
35#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 30pub type PatId = Idx<Pat>;
36pub struct PatId(RawId);
37impl_arena_id!(PatId);
38 31
39#[derive(Debug, Clone, Eq, PartialEq)] 32#[derive(Debug, Clone, Eq, PartialEq)]
40pub enum Literal { 33pub enum Literal {
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 24adc8153..b687ce2b2 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -43,7 +43,7 @@ pub enum TypeParamProvenance {
43/// Data about the generic parameters of a function, struct, impl, etc. 43/// Data about the generic parameters of a function, struct, impl, etc.
44#[derive(Clone, PartialEq, Eq, Debug)] 44#[derive(Clone, PartialEq, Eq, Debug)]
45pub struct GenericParams { 45pub struct GenericParams {
46 pub types: Arena<LocalTypeParamId, TypeParamData>, 46 pub types: Arena<TypeParamData>,
47 // lifetimes: Arena<LocalLifetimeParamId, LifetimeParamData>, 47 // lifetimes: Arena<LocalLifetimeParamId, LifetimeParamData>,
48 pub where_predicates: Vec<WherePredicate>, 48 pub where_predicates: Vec<WherePredicate>,
49} 49}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index d0f043ed0..516dd773e 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -50,7 +50,7 @@ use hir_expand::{
50 ast_id_map::FileAstId, eager::expand_eager_macro, hygiene::Hygiene, AstId, HirFileId, InFile, 50 ast_id_map::FileAstId, eager::expand_eager_macro, hygiene::Hygiene, AstId, HirFileId, InFile,
51 MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 51 MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
52}; 52};
53use ra_arena::{impl_arena_id, RawId}; 53use ra_arena::Idx;
54use ra_db::{impl_intern_key, salsa, CrateId}; 54use ra_db::{impl_intern_key, salsa, CrateId};
55use ra_syntax::{ast, AstNode}; 55use ra_syntax::{ast, AstNode};
56 56
@@ -64,9 +64,7 @@ pub struct ModuleId {
64} 64}
65 65
66/// An ID of a module, **local** to a specific crate 66/// An ID of a module, **local** to a specific crate
67#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 67pub type LocalModuleId = Idx<nameres::ModuleData>;
68pub struct LocalModuleId(RawId);
69impl_arena_id!(LocalModuleId);
70 68
71#[derive(Debug, Clone, PartialEq, Eq, Hash)] 69#[derive(Debug, Clone, PartialEq, Eq, Hash)]
72pub struct ItemLoc<N: AstNode> { 70pub struct ItemLoc<N: AstNode> {
@@ -127,9 +125,7 @@ pub struct EnumVariantId {
127 pub local_id: LocalEnumVariantId, 125 pub local_id: LocalEnumVariantId,
128} 126}
129 127
130#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 128pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
131pub struct LocalEnumVariantId(RawId);
132impl_arena_id!(LocalEnumVariantId);
133 129
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 130#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
135pub struct StructFieldId { 131pub struct StructFieldId {
@@ -137,9 +133,7 @@ pub struct StructFieldId {
137 pub local_id: LocalStructFieldId, 133 pub local_id: LocalStructFieldId,
138} 134}
139 135
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 136pub type LocalStructFieldId = Idx<adt::StructFieldData>;
141pub struct LocalStructFieldId(RawId);
142impl_arena_id!(LocalStructFieldId);
143 137
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 138#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
145pub struct ConstId(salsa::InternId); 139pub struct ConstId(salsa::InternId);
@@ -172,9 +166,7 @@ pub struct TypeParamId {
172 pub local_id: LocalTypeParamId, 166 pub local_id: LocalTypeParamId,
173} 167}
174 168
175#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 169pub type LocalTypeParamId = Idx<generics::TypeParamData>;
176pub struct LocalTypeParamId(RawId);
177impl_arena_id!(LocalTypeParamId);
178 170
179macro_rules! impl_froms { 171macro_rules! impl_froms {
180 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { 172 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index be53313ee..40bdc34f5 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -77,7 +77,7 @@ use crate::{
77#[derive(Debug, PartialEq, Eq)] 77#[derive(Debug, PartialEq, Eq)]
78pub struct CrateDefMap { 78pub struct CrateDefMap {
79 pub root: LocalModuleId, 79 pub root: LocalModuleId,
80 pub modules: Arena<LocalModuleId, ModuleData>, 80 pub modules: Arena<ModuleData>,
81 pub(crate) krate: CrateId, 81 pub(crate) krate: CrateId,
82 /// The prelude module for this crate. This either comes from an import 82 /// The prelude module for this crate. This either comes from an import
83 /// marked with the `prelude_import` attribute, or (in the normal case) from 83 /// marked with the `prelude_import` attribute, or (in the normal case) from
@@ -187,7 +187,7 @@ impl CrateDefMap {
187 }); 187 });
188 let def_map = { 188 let def_map = {
189 let edition = db.crate_graph()[krate].edition; 189 let edition = db.crate_graph()[krate].edition;
190 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 190 let mut modules: Arena<ModuleData> = Arena::default();
191 let root = modules.alloc(ModuleData::default()); 191 let root = modules.alloc(ModuleData::default());
192 CrateDefMap { 192 CrateDefMap {
193 krate, 193 krate,
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 7a042e69f..5b292c250 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -966,7 +966,7 @@ mod tests {
966 966
967 let def_map = { 967 let def_map = {
968 let edition = db.crate_graph()[krate].edition; 968 let edition = db.crate_graph()[krate].edition;
969 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 969 let mut modules: Arena<ModuleData> = Arena::default();
970 let root = modules.alloc(ModuleData::default()); 970 let root = modules.alloc(ModuleData::default());
971 CrateDefMap { 971 CrateDefMap {
972 krate, 972 krate,
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 0e4931f58..1631e87b8 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -12,7 +12,7 @@ use hir_expand::{
12 hygiene::Hygiene, 12 hygiene::Hygiene,
13 name::{AsName, Name}, 13 name::{AsName, Name},
14}; 14};
15use ra_arena::{impl_arena_id, Arena, RawId}; 15use ra_arena::{Arena, Idx};
16use ra_prof::profile; 16use ra_prof::profile;
17use ra_syntax::{ 17use ra_syntax::{
18 ast::{self, AttrsOwner, NameOwner, VisibilityOwner}, 18 ast::{self, AttrsOwner, NameOwner, VisibilityOwner},
@@ -34,11 +34,11 @@ use crate::{
34/// on most edits. 34/// on most edits.
35#[derive(Debug, Default, PartialEq, Eq)] 35#[derive(Debug, Default, PartialEq, Eq)]
36pub struct RawItems { 36pub struct RawItems {
37 modules: Arena<Module, ModuleData>, 37 modules: Arena<ModuleData>,
38 imports: Arena<Import, ImportData>, 38 imports: Arena<ImportData>,
39 defs: Arena<Def, DefData>, 39 defs: Arena<DefData>,
40 macros: Arena<Macro, MacroData>, 40 macros: Arena<MacroData>,
41 impls: Arena<Impl, ImplData>, 41 impls: Arena<ImplData>,
42 /// items for top-level module 42 /// items for top-level module
43 items: Vec<RawItem>, 43 items: Vec<RawItem>,
44} 44}
@@ -68,9 +68,9 @@ impl RawItems {
68 } 68 }
69} 69}
70 70
71impl Index<Module> for RawItems { 71impl Index<Idx<ModuleData>> for RawItems {
72 type Output = ModuleData; 72 type Output = ModuleData;
73 fn index(&self, idx: Module) -> &ModuleData { 73 fn index(&self, idx: Idx<ModuleData>) -> &ModuleData {
74 &self.modules[idx] 74 &self.modules[idx]
75 } 75 }
76} 76}
@@ -82,23 +82,23 @@ impl Index<Import> for RawItems {
82 } 82 }
83} 83}
84 84
85impl Index<Def> for RawItems { 85impl Index<Idx<DefData>> for RawItems {
86 type Output = DefData; 86 type Output = DefData;
87 fn index(&self, idx: Def) -> &DefData { 87 fn index(&self, idx: Idx<DefData>) -> &DefData {
88 &self.defs[idx] 88 &self.defs[idx]
89 } 89 }
90} 90}
91 91
92impl Index<Macro> for RawItems { 92impl Index<Idx<MacroData>> for RawItems {
93 type Output = MacroData; 93 type Output = MacroData;
94 fn index(&self, idx: Macro) -> &MacroData { 94 fn index(&self, idx: Idx<MacroData>) -> &MacroData {
95 &self.macros[idx] 95 &self.macros[idx]
96 } 96 }
97} 97}
98 98
99impl Index<Impl> for RawItems { 99impl Index<Idx<ImplData>> for RawItems {
100 type Output = ImplData; 100 type Output = ImplData;
101 fn index(&self, idx: Impl) -> &ImplData { 101 fn index(&self, idx: Idx<ImplData>) -> &ImplData {
102 &self.impls[idx] 102 &self.impls[idx]
103 } 103 }
104} 104}
@@ -111,17 +111,13 @@ pub(super) struct RawItem {
111 111
112#[derive(Debug, PartialEq, Eq, Clone, Copy)] 112#[derive(Debug, PartialEq, Eq, Clone, Copy)]
113pub(super) enum RawItemKind { 113pub(super) enum RawItemKind {
114 Module(Module), 114 Module(Idx<ModuleData>),
115 Import(Import), 115 Import(Import),
116 Def(Def), 116 Def(Idx<DefData>),
117 Macro(Macro), 117 Macro(Idx<MacroData>),
118 Impl(Impl), 118 Impl(Idx<ImplData>),
119} 119}
120 120
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
122pub(super) struct Module(RawId);
123impl_arena_id!(Module);
124
125#[derive(Debug, PartialEq, Eq)] 121#[derive(Debug, PartialEq, Eq)]
126pub(super) enum ModuleData { 122pub(super) enum ModuleData {
127 Declaration { 123 Declaration {
@@ -137,9 +133,7 @@ pub(super) enum ModuleData {
137 }, 133 },
138} 134}
139 135
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 136pub(crate) type Import = Idx<ImportData>;
141pub(crate) struct Import(RawId);
142impl_arena_id!(Import);
143 137
144#[derive(Debug, Clone, PartialEq, Eq)] 138#[derive(Debug, Clone, PartialEq, Eq)]
145pub struct ImportData { 139pub struct ImportData {
@@ -152,9 +146,7 @@ pub struct ImportData {
152 pub(super) visibility: RawVisibility, 146 pub(super) visibility: RawVisibility,
153} 147}
154 148
155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 149// type Def = Idx<DefData>;
156pub(super) struct Def(RawId);
157impl_arena_id!(Def);
158 150
159#[derive(Debug, PartialEq, Eq)] 151#[derive(Debug, PartialEq, Eq)]
160pub(super) struct DefData { 152pub(super) struct DefData {
@@ -190,10 +182,6 @@ impl DefKind {
190 } 182 }
191} 183}
192 184
193#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
194pub(super) struct Macro(RawId);
195impl_arena_id!(Macro);
196
197#[derive(Debug, PartialEq, Eq)] 185#[derive(Debug, PartialEq, Eq)]
198pub(super) struct MacroData { 186pub(super) struct MacroData {
199 pub(super) ast_id: FileAstId<ast::MacroCall>, 187 pub(super) ast_id: FileAstId<ast::MacroCall>,
@@ -203,10 +191,6 @@ pub(super) struct MacroData {
203 pub(super) builtin: bool, 191 pub(super) builtin: bool,
204} 192}
205 193
206#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
207pub(super) struct Impl(RawId);
208impl_arena_id!(Impl);
209
210#[derive(Debug, PartialEq, Eq)] 194#[derive(Debug, PartialEq, Eq)]
211pub(super) struct ImplData { 195pub(super) struct ImplData {
212 pub(super) ast_id: FileAstId<ast::ImplDef>, 196 pub(super) ast_id: FileAstId<ast::ImplDef>,
@@ -220,7 +204,11 @@ struct RawItemsCollector {
220} 204}
221 205
222impl RawItemsCollector { 206impl RawItemsCollector {
223 fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { 207 fn process_module(
208 &mut self,
209 current_module: Option<Idx<ModuleData>>,
210 body: impl ast::ModuleItemOwner,
211 ) {
224 for item_or_macro in body.items_with_macros() { 212 for item_or_macro in body.items_with_macros() {
225 match item_or_macro { 213 match item_or_macro {
226 ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m), 214 ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m),
@@ -229,7 +217,7 @@ impl RawItemsCollector {
229 } 217 }
230 } 218 }
231 219
232 fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) { 220 fn add_item(&mut self, current_module: Option<Idx<ModuleData>>, item: ast::ModuleItem) {
233 let attrs = self.parse_attrs(&item); 221 let attrs = self.parse_attrs(&item);
234 let visibility = RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene); 222 let visibility = RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene);
235 let (kind, name) = match item { 223 let (kind, name) = match item {
@@ -285,7 +273,7 @@ impl RawItemsCollector {
285 } 273 }
286 } 274 }
287 275
288 fn add_module(&mut self, current_module: Option<Module>, module: ast::Module) { 276 fn add_module(&mut self, current_module: Option<Idx<ModuleData>>, module: ast::Module) {
289 let name = match module.name() { 277 let name = match module.name() {
290 Some(it) => it.as_name(), 278 Some(it) => it.as_name(),
291 None => return, 279 None => return,
@@ -315,7 +303,7 @@ impl RawItemsCollector {
315 tested_by!(name_res_works_for_broken_modules); 303 tested_by!(name_res_works_for_broken_modules);
316 } 304 }
317 305
318 fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { 306 fn add_use_item(&mut self, current_module: Option<Idx<ModuleData>>, use_item: ast::UseItem) {
319 // FIXME: cfg_attr 307 // FIXME: cfg_attr
320 let is_prelude = use_item.has_atom_attr("prelude_import"); 308 let is_prelude = use_item.has_atom_attr("prelude_import");
321 let attrs = self.parse_attrs(&use_item); 309 let attrs = self.parse_attrs(&use_item);
@@ -345,7 +333,7 @@ impl RawItemsCollector {
345 333
346 fn add_extern_crate_item( 334 fn add_extern_crate_item(
347 &mut self, 335 &mut self,
348 current_module: Option<Module>, 336 current_module: Option<Idx<ModuleData>>,
349 extern_crate: ast::ExternCrateItem, 337 extern_crate: ast::ExternCrateItem,
350 ) { 338 ) {
351 if let Some(name_ref) = extern_crate.name_ref() { 339 if let Some(name_ref) = extern_crate.name_ref() {
@@ -371,7 +359,7 @@ impl RawItemsCollector {
371 } 359 }
372 } 360 }
373 361
374 fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { 362 fn add_macro(&mut self, current_module: Option<Idx<ModuleData>>, m: ast::MacroCall) {
375 let attrs = self.parse_attrs(&m); 363 let attrs = self.parse_attrs(&m);
376 let path = match m.path().and_then(|path| ModPath::from_src(path, &self.hygiene)) { 364 let path = match m.path().and_then(|path| ModPath::from_src(path, &self.hygiene)) {
377 Some(it) => it, 365 Some(it) => it,
@@ -391,19 +379,29 @@ impl RawItemsCollector {
391 self.push_item(current_module, attrs, RawItemKind::Macro(m)); 379 self.push_item(current_module, attrs, RawItemKind::Macro(m));
392 } 380 }
393 381
394 fn add_impl(&mut self, current_module: Option<Module>, imp: ast::ImplDef) { 382 fn add_impl(&mut self, current_module: Option<Idx<ModuleData>>, imp: ast::ImplDef) {
395 let attrs = self.parse_attrs(&imp); 383 let attrs = self.parse_attrs(&imp);
396 let ast_id = self.source_ast_id_map.ast_id(&imp); 384 let ast_id = self.source_ast_id_map.ast_id(&imp);
397 let imp = self.raw_items.impls.alloc(ImplData { ast_id }); 385 let imp = self.raw_items.impls.alloc(ImplData { ast_id });
398 self.push_item(current_module, attrs, RawItemKind::Impl(imp)) 386 self.push_item(current_module, attrs, RawItemKind::Impl(imp))
399 } 387 }
400 388
401 fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) { 389 fn push_import(
390 &mut self,
391 current_module: Option<Idx<ModuleData>>,
392 attrs: Attrs,
393 data: ImportData,
394 ) {
402 let import = self.raw_items.imports.alloc(data); 395 let import = self.raw_items.imports.alloc(data);
403 self.push_item(current_module, attrs, RawItemKind::Import(import)) 396 self.push_item(current_module, attrs, RawItemKind::Import(import))
404 } 397 }
405 398
406 fn push_item(&mut self, current_module: Option<Module>, attrs: Attrs, kind: RawItemKind) { 399 fn push_item(
400 &mut self,
401 current_module: Option<Idx<ModuleData>>,
402 attrs: Attrs,
403 kind: RawItemKind,
404 ) {
407 match current_module { 405 match current_module {
408 Some(module) => match &mut self.raw_items.modules[module] { 406 Some(module) => match &mut self.raw_items.modules[module] {
409 ModuleData::Definition { items, .. } => items, 407 ModuleData::Definition { items, .. } => items,
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
index b502a4079..37fcdfb8c 100644
--- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
@@ -710,9 +710,7 @@ fn unresolved_module_diagnostics() {
710 @r###" 710 @r###"
711 [ 711 [
712 UnresolvedModule { 712 UnresolvedModule {
713 module: LocalModuleId( 713 module: Idx::<ModuleData>(0),
714 0,
715 ),
716 declaration: InFile { 714 declaration: InFile {
717 file_id: HirFileId( 715 file_id: HirFileId(
718 FileId( 716 FileId(
@@ -722,9 +720,7 @@ fn unresolved_module_diagnostics() {
722 ), 720 ),
723 ), 721 ),
724 value: FileAstId { 722 value: FileAstId {
725 raw: ErasedFileAstId( 723 raw: Idx::<SyntaxNodePtr>(1),
726 1,
727 ),
728 _ty: PhantomData, 724 _ty: PhantomData,
729 }, 725 },
730 }, 726 },
diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs
index 9769e88df..ced07577d 100644
--- a/crates/ra_hir_def/src/trace.rs
+++ b/crates/ra_hir_def/src/trace.rs
@@ -9,28 +9,28 @@
9//! absolute offsets. The `Trace` structure (inspired, at least in name, by 9//! absolute offsets. The `Trace` structure (inspired, at least in name, by
10//! Kotlin's `BindingTrace`) allows use the same code to compute both 10//! Kotlin's `BindingTrace`) allows use the same code to compute both
11//! projections. 11//! projections.
12use ra_arena::{map::ArenaMap, Arena, ArenaId, RawId}; 12use ra_arena::{map::ArenaMap, Arena, Idx, RawId};
13 13
14pub(crate) struct Trace<ID: ArenaId, T, V> { 14pub(crate) struct Trace<T, V> {
15 arena: Option<Arena<ID, T>>, 15 arena: Option<Arena<T>>,
16 map: Option<ArenaMap<ID, V>>, 16 map: Option<ArenaMap<Idx<T>, V>>,
17 len: u32, 17 len: u32,
18} 18}
19 19
20impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { 20impl<T, V> Trace<T, V> {
21 pub(crate) fn new_for_arena() -> Trace<ID, T, V> { 21 pub(crate) fn new_for_arena() -> Trace<T, V> {
22 Trace { arena: Some(Arena::default()), map: None, len: 0 } 22 Trace { arena: Some(Arena::default()), map: None, len: 0 }
23 } 23 }
24 24
25 pub(crate) fn new_for_map() -> Trace<ID, T, V> { 25 pub(crate) fn new_for_map() -> Trace<T, V> {
26 Trace { arena: None, map: Some(ArenaMap::default()), len: 0 } 26 Trace { arena: None, map: Some(ArenaMap::default()), len: 0 }
27 } 27 }
28 28
29 pub(crate) fn alloc(&mut self, value: impl FnOnce() -> V, data: impl FnOnce() -> T) -> ID { 29 pub(crate) fn alloc(&mut self, value: impl FnOnce() -> V, data: impl FnOnce() -> T) -> Idx<T> {
30 let id = if let Some(arena) = &mut self.arena { 30 let id = if let Some(arena) = &mut self.arena {
31 arena.alloc(data()) 31 arena.alloc(data())
32 } else { 32 } else {
33 let id = ID::from_raw(RawId::from(self.len)); 33 let id = Idx::<T>::from_raw(RawId::from(self.len));
34 self.len += 1; 34 self.len += 1;
35 id 35 id
36 }; 36 };
@@ -41,11 +41,11 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
41 id 41 id
42 } 42 }
43 43
44 pub(crate) fn into_arena(mut self) -> Arena<ID, T> { 44 pub(crate) fn into_arena(mut self) -> Arena<T> {
45 self.arena.take().unwrap() 45 self.arena.take().unwrap()
46 } 46 }
47 47
48 pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { 48 pub(crate) fn into_map(mut self) -> ArenaMap<Idx<T>, V> {
49 self.map.take().unwrap() 49 self.map.take().unwrap()
50 } 50 }
51} 51}
diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs
index a764bdf24..a6644d55f 100644
--- a/crates/ra_hir_expand/src/ast_id_map.rs
+++ b/crates/ra_hir_expand/src/ast_id_map.rs
@@ -10,7 +10,7 @@ use std::{
10 marker::PhantomData, 10 marker::PhantomData,
11}; 11};
12 12
13use ra_arena::{impl_arena_id, Arena, RawId}; 13use ra_arena::{Arena, Idx};
14use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; 14use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
15 15
16/// `AstId` points to an AST node in a specific file. 16/// `AstId` points to an AST node in a specific file.
@@ -49,14 +49,12 @@ impl<N: AstNode> FileAstId<N> {
49 } 49 }
50} 50}
51 51
52#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 52type ErasedFileAstId = Idx<SyntaxNodePtr>;
53struct ErasedFileAstId(RawId);
54impl_arena_id!(ErasedFileAstId);
55 53
56/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back. 54/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
57#[derive(Debug, PartialEq, Eq, Default)] 55#[derive(Debug, PartialEq, Eq, Default)]
58pub struct AstIdMap { 56pub struct AstIdMap {
59 arena: Arena<ErasedFileAstId, SyntaxNodePtr>, 57 arena: Arena<SyntaxNodePtr>,
60} 58}
61 59
62impl AstIdMap { 60impl AstIdMap {
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 43dbd096a..c2857dbfc 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -7,7 +7,7 @@ use std::{
7 7
8use anyhow::{Context, Result}; 8use anyhow::{Context, Result};
9use cargo_metadata::{CargoOpt, Message, MetadataCommand, PackageId}; 9use cargo_metadata::{CargoOpt, Message, MetadataCommand, PackageId};
10use ra_arena::{impl_arena_id, Arena, RawId}; 10use ra_arena::{Arena, Idx};
11use ra_cargo_watch::run_cargo; 11use ra_cargo_watch::run_cargo;
12use ra_db::Edition; 12use ra_db::Edition;
13use rustc_hash::FxHashMap; 13use rustc_hash::FxHashMap;
@@ -22,8 +22,8 @@ use serde::Deserialize;
22/// concepts. 22/// concepts.
23#[derive(Debug, Clone)] 23#[derive(Debug, Clone)]
24pub struct CargoWorkspace { 24pub struct CargoWorkspace {
25 packages: Arena<Package, PackageData>, 25 packages: Arena<PackageData>,
26 targets: Arena<Target, TargetData>, 26 targets: Arena<TargetData>,
27 workspace_root: PathBuf, 27 workspace_root: PathBuf,
28} 28}
29 29
@@ -69,13 +69,9 @@ impl Default for CargoFeatures {
69 } 69 }
70} 70}
71 71
72#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 72pub type Package = Idx<PackageData>;
73pub struct Package(RawId);
74impl_arena_id!(Package);
75 73
76#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 74pub type Target = Idx<TargetData>;
77pub struct Target(RawId);
78impl_arena_id!(Target);
79 75
80#[derive(Debug, Clone)] 76#[derive(Debug, Clone)]
81pub struct PackageData { 77pub struct PackageData {
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs
index 4ac4fa14d..55ff5ad80 100644
--- a/crates/ra_project_model/src/sysroot.rs
+++ b/crates/ra_project_model/src/sysroot.rs
@@ -7,16 +7,14 @@ use std::{
7 process::{Command, Output}, 7 process::{Command, Output},
8}; 8};
9 9
10use ra_arena::{impl_arena_id, Arena, RawId}; 10use ra_arena::{Arena, Idx};
11 11
12#[derive(Default, Debug, Clone)] 12#[derive(Default, Debug, Clone)]
13pub struct Sysroot { 13pub struct Sysroot {
14 crates: Arena<SysrootCrate, SysrootCrateData>, 14 crates: Arena<SysrootCrateData>,
15} 15}
16 16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 17pub type SysrootCrate = Idx<SysrootCrateData>;
18pub struct SysrootCrate(RawId);
19impl_arena_id!(SysrootCrate);
20 18
21#[derive(Debug, Clone)] 19#[derive(Debug, Clone)]
22pub struct SysrootCrateData { 20pub struct SysrootCrateData {