aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-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
12 files changed, 85 insertions, 112 deletions
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}