aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 22:31:32 +0000
committerAleksey Kladov <[email protected]>2019-01-24 22:31:32 +0000
commit0f2f3a21e7e624f920d182869896347af309e909 (patch)
tree8c16d0a479021c2d558a865df94eb01316a208b2 /crates
parent00ba70a0957b8af2813940787238a733298dfa5f (diff)
Migrate trait & type to new ids
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs35
-rw-r--r--crates/ra_hir/src/code_model_impl.rs15
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs7
-rw-r--r--crates/ra_hir/src/generics.rs23
-rw-r--r--crates/ra_hir/src/ids.rs38
-rw-r--r--crates/ra_hir/src/nameres/lower.rs85
-rw-r--r--crates/ra_hir/src/source_binder.rs4
-rw-r--r--crates/ra_hir/src/ty.rs4
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs7
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs8
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs59
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
-rw-r--r--crates/ra_syntax/src/grammar.ron4
13 files changed, 104 insertions, 186 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index d82dda79a..e2979617d 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -13,10 +13,9 @@ use crate::{
13 ty::{InferenceResult, VariantDef}, 13 ty::{InferenceResult, VariantDef},
14 adt::VariantData, 14 adt::VariantData,
15 generics::GenericParams, 15 generics::GenericParams,
16 code_model_impl::def_id_to_ast,
17 docs::{Documentation, Docs, docs_from_ast}, 16 docs::{Documentation, Docs, docs_from_ast},
18 module_tree::ModuleId, 17 module_tree::ModuleId,
19 ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef, ConstId, StaticId}, 18 ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef, ConstId, StaticId, TraitId, TypeId},
20}; 19};
21 20
22/// hir::Crate describes a single crate. It's the main interface with which 21/// hir::Crate describes a single crate. It's the main interface with which
@@ -47,8 +46,6 @@ impl Crate {
47 46
48#[derive(Debug)] 47#[derive(Debug)]
49pub enum Def { 48pub enum Def {
50 Trait(Trait),
51 Type(Type),
52 Item, 49 Item,
53} 50}
54 51
@@ -68,6 +65,8 @@ pub enum ModuleDef {
68 EnumVariant(EnumVariant), 65 EnumVariant(EnumVariant),
69 Const(Const), 66 Const(Const),
70 Static(Static), 67 Static(Static),
68 Trait(Trait),
69 Type(Type),
71 // Can't be directly declared, but can be imported. 70 // Can't be directly declared, but can be imported.
72 Def(DefId), 71 Def(DefId),
73} 72}
@@ -78,7 +77,9 @@ impl_froms!(
78 Enum, 77 Enum,
79 EnumVariant, 78 EnumVariant,
80 Const, 79 Const,
81 Static 80 Static,
81 Trait,
82 Type
82); 83);
83 84
84impl From<DefId> for ModuleDef { 85impl From<DefId> for ModuleDef {
@@ -428,22 +429,18 @@ impl Docs for Static {
428 } 429 }
429} 430}
430 431
431#[derive(Debug, Clone, PartialEq, Eq, Hash)] 432#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
432pub struct Trait { 433pub struct Trait {
433 pub(crate) def_id: DefId, 434 pub(crate) id: TraitId,
434} 435}
435 436
436impl Trait { 437impl Trait {
437 pub(crate) fn new(def_id: DefId) -> Trait {
438 Trait { def_id }
439 }
440
441 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 438 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
442 def_id_to_ast(db, self.def_id) 439 self.id.source(db)
443 } 440 }
444 441
445 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 442 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
446 db.generic_params(self.def_id.into()) 443 db.generic_params((*self).into())
447 } 444 }
448} 445}
449 446
@@ -453,22 +450,18 @@ impl Docs for Trait {
453 } 450 }
454} 451}
455 452
456#[derive(Debug, Clone, PartialEq, Eq, Hash)] 453#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
457pub struct Type { 454pub struct Type {
458 pub(crate) def_id: DefId, 455 pub(crate) id: TypeId,
459} 456}
460 457
461impl Type { 458impl Type {
462 pub(crate) fn new(def_id: DefId) -> Type {
463 Type { def_id }
464 }
465
466 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) { 459 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
467 def_id_to_ast(db, self.def_id) 460 self.id.source(db)
468 } 461 }
469 462
470 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { 463 pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
471 db.generic_params(self.def_id.into()) 464 db.generic_params((*self).into())
472 } 465 }
473} 466}
474 467
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs
index 0cea9f7b6..1f28fab74 100644
--- a/crates/ra_hir/src/code_model_impl.rs
+++ b/crates/ra_hir/src/code_model_impl.rs
@@ -1,18 +1,3 @@
1mod krate; // `crate` is invalid ident :( 1mod krate; // `crate` is invalid ident :(
2mod module; 2mod module;
3pub(crate) mod function; 3pub(crate) mod function;
4
5use ra_syntax::{AstNode, TreeArc};
6
7use crate::{HirDatabase, DefId, HirFileId};
8
9pub(crate) fn def_id_to_ast<N: AstNode>(
10 db: &impl HirDatabase,
11 def_id: DefId,
12) -> (HirFileId, TreeArc<N>) {
13 let (file_id, syntax) = def_id.source(db);
14 let ast = N::cast(&syntax)
15 .unwrap_or_else(|| panic!("def points to wrong source {:?} {:?}", def_id, syntax))
16 .to_owned();
17 (file_id, ast)
18}
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 1518825c7..6419d3934 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -147,17 +147,12 @@ impl Module {
147 None => PerNs::none(), 147 None => PerNs::none(),
148 } 148 }
149 } 149 }
150 ModuleDef::Function(_) 150 _ => {
151 | ModuleDef::Struct(_)
152 | ModuleDef::Const(_)
153 | ModuleDef::Static(_)
154 | ModuleDef::EnumVariant(_) => {
155 // could be an inherent method call in UFCS form 151 // could be an inherent method call in UFCS form
156 // (`Struct::method`), or some other kind of associated 152 // (`Struct::method`), or some other kind of associated
157 // item... Which we currently don't handle (TODO) 153 // item... Which we currently don't handle (TODO)
158 PerNs::none() 154 PerNs::none()
159 } 155 }
160 ModuleDef::Def(_) => PerNs::none(),
161 }; 156 };
162 } 157 }
163 curr_per_ns 158 curr_per_ns
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index a8cacbb4a..64c20a462 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -5,9 +5,9 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use ra_syntax::ast::{self, AstNode, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
9 9
10use crate::{db::HirDatabase, DefId, Name, AsName, Function, Struct, Enum}; 10use crate::{db::HirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type};
11 11
12/// Data about a generic parameter (to a function, struct, impl, ...). 12/// Data about a generic parameter (to a function, struct, impl, ...).
13#[derive(Clone, PartialEq, Eq, Debug)] 13#[derive(Clone, PartialEq, Eq, Debug)]
@@ -27,15 +27,10 @@ pub enum GenericDef {
27 Function(Function), 27 Function(Function),
28 Struct(Struct), 28 Struct(Struct),
29 Enum(Enum), 29 Enum(Enum),
30 Def(DefId), 30 Trait(Trait),
31} 31 Type(Type),
32impl_froms!(GenericDef: Function, Struct, Enum);
33
34impl From<DefId> for GenericDef {
35 fn from(def_id: DefId) -> GenericDef {
36 GenericDef::Def(def_id)
37 }
38} 32}
33impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type);
39 34
40impl GenericParams { 35impl GenericParams {
41 pub(crate) fn generic_params_query( 36 pub(crate) fn generic_params_query(
@@ -47,12 +42,8 @@ impl GenericParams {
47 GenericDef::Function(it) => generics.fill(&*it.source(db).1), 42 GenericDef::Function(it) => generics.fill(&*it.source(db).1),
48 GenericDef::Struct(it) => generics.fill(&*it.source(db).1), 43 GenericDef::Struct(it) => generics.fill(&*it.source(db).1),
49 GenericDef::Enum(it) => generics.fill(&*it.source(db).1), 44 GenericDef::Enum(it) => generics.fill(&*it.source(db).1),
50 GenericDef::Def(def_id) => { 45 GenericDef::Trait(it) => generics.fill(&*it.source(db).1),
51 let (_file_id, node) = def_id.source(db); 46 GenericDef::Type(it) => generics.fill(&*it.source(db).1),
52 if let Some(type_param_list) = node.children().find_map(ast::TypeParamList::cast) {
53 generics.fill_params(type_param_list)
54 }
55 }
56 } 47 }
57 48
58 Arc::new(generics) 49 Arc::new(generics)
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 2cc175bda..311c0b98a 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -9,7 +9,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
9 9
10use crate::{ 10use crate::{
11 HirDatabase, Def, 11 HirDatabase, Def,
12 Module, Trait, Type, 12 Module,
13}; 13};
14 14
15#[derive(Debug, Default)] 15#[derive(Debug, Default)]
@@ -22,6 +22,8 @@ pub struct HirInterner {
22 enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>, 22 enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>,
23 consts: LocationIntener<ItemLoc<ast::ConstDef>, ConstId>, 23 consts: LocationIntener<ItemLoc<ast::ConstDef>, ConstId>,
24 statics: LocationIntener<ItemLoc<ast::StaticDef>, StaticId>, 24 statics: LocationIntener<ItemLoc<ast::StaticDef>, StaticId>,
25 traits: LocationIntener<ItemLoc<ast::TraitDef>, TraitId>,
26 types: LocationIntener<ItemLoc<ast::TypeDef>, TypeId>,
25} 27}
26 28
27impl HirInterner { 29impl HirInterner {
@@ -279,6 +281,24 @@ impl AstItemDef<ast::StaticDef> for StaticId {
279 } 281 }
280} 282}
281 283
284#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
285pub struct TraitId(RawId);
286impl_arena_id!(TraitId);
287impl AstItemDef<ast::TraitDef> for TraitId {
288 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::TraitDef>, Self> {
289 &interner.traits
290 }
291}
292
293#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
294pub struct TypeId(RawId);
295impl_arena_id!(TypeId);
296impl AstItemDef<ast::TypeDef> for TypeId {
297 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::TypeDef>, Self> {
298 &interner.types
299 }
300}
301
282/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) 302/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
283/// in a specific module. 303/// in a specific module.
284#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 304#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -294,8 +314,6 @@ pub struct DefLoc {
294 314
295#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 315#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
296pub(crate) enum DefKind { 316pub(crate) enum DefKind {
297 Trait,
298 Type,
299 Item, 317 Item,
300 // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the 318 // /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the
301 // /// name `Foo` needs to resolve to different types depending on whether we 319 // /// name `Foo` needs to resolve to different types depending on whether we
@@ -317,23 +335,9 @@ impl DefId {
317 pub fn resolve(self, db: &impl HirDatabase) -> Def { 335 pub fn resolve(self, db: &impl HirDatabase) -> Def {
318 let loc = self.loc(db); 336 let loc = self.loc(db);
319 match loc.kind { 337 match loc.kind {
320 DefKind::Trait => {
321 let def = Trait::new(self);
322 Def::Trait(def)
323 }
324 DefKind::Type => {
325 let def = Type::new(self);
326 Def::Type(def)
327 }
328 DefKind::Item => Def::Item, 338 DefKind::Item => Def::Item,
329 } 339 }
330 } 340 }
331
332 pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) {
333 let loc = self.loc(db);
334 let syntax = db.file_item(loc.source_item_id);
335 (loc.source_item_id.file_id, syntax)
336 }
337} 341}
338 342
339impl DefLoc { 343impl DefLoc {
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index 6a86e5fd4..b4fe99ea7 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -1,16 +1,16 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 SyntaxKind, AstNode, SourceFile, TreeArc, AstPtr, 4 AstNode, SourceFile, TreeArc, AstPtr,
5 ast::{self, ModuleItemOwner, NameOwner}, 5 ast::{self, ModuleItemOwner, NameOwner},
6}; 6};
7use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 7use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9 9
10use crate::{ 10use crate::{
11 SourceItemId, Path, ModuleSource, HirDatabase, Name, SourceFileItems, 11 SourceItemId, Path, ModuleSource, HirDatabase, Name,
12 HirFileId, MacroCallLoc, AsName, PerNs, DefKind, DefLoc, Function, 12 HirFileId, MacroCallLoc, AsName, PerNs, Function,
13 ModuleDef, Module, Struct, Enum, Const, Static, 13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type,
14 ids::LocationCtx, 14 ids::LocationCtx,
15}; 15};
16 16
@@ -115,7 +115,7 @@ impl LoweredModule {
115 for item in items { 115 for item in items {
116 match item { 116 match item {
117 ast::ItemOrMacro::Item(it) => { 117 ast::ItemOrMacro::Item(it) => {
118 self.add_def_id(source_map, db, module, file_id, &file_items, it); 118 self.add_def_id(source_map, db, module, file_id, it);
119 } 119 }
120 ast::ItemOrMacro::Macro(macro_call) => { 120 ast::ItemOrMacro::Macro(macro_call) => {
121 let item_id = file_items.id_of_unchecked(macro_call.syntax()); 121 let item_id = file_items.id_of_unchecked(macro_call.syntax());
@@ -128,10 +128,9 @@ impl LoweredModule {
128 }; 128 };
129 let id = loc.id(db); 129 let id = loc.id(db);
130 let file_id = HirFileId::from(id); 130 let file_id = HirFileId::from(id);
131 let file_items = db.file_items(file_id);
132 //FIXME: expand recursively 131 //FIXME: expand recursively
133 for item in db.hir_source_file(file_id).items() { 132 for item in db.hir_source_file(file_id).items() {
134 self.add_def_id(source_map, db, module, file_id, &file_items, item); 133 self.add_def_id(source_map, db, module, file_id, item);
135 } 134 }
136 } 135 }
137 } 136 }
@@ -144,18 +143,16 @@ impl LoweredModule {
144 db: &impl HirDatabase, 143 db: &impl HirDatabase,
145 module: Module, 144 module: Module,
146 file_id: HirFileId, 145 file_id: HirFileId,
147 file_items: &SourceFileItems,
148 item: &ast::ModuleItem, 146 item: &ast::ModuleItem,
149 ) { 147 ) {
150 let ctx = LocationCtx::new(db, module, file_id); 148 let ctx = LocationCtx::new(db, module, file_id);
151 let name = match item.kind() { 149 match item.kind() {
152 ast::ModuleItemKind::StructDef(it) => { 150 ast::ModuleItemKind::StructDef(it) => {
153 if let Some(name) = it.name() { 151 if let Some(name) = it.name() {
154 let s = Struct { id: ctx.to_def(it) }; 152 let s = Struct { id: ctx.to_def(it) };
155 let s: ModuleDef = s.into(); 153 let s: ModuleDef = s.into();
156 self.declarations.insert(name.as_name(), PerNs::both(s, s)); 154 self.declarations.insert(name.as_name(), PerNs::both(s, s));
157 } 155 }
158 return;
159 } 156 }
160 ast::ModuleItemKind::EnumDef(it) => { 157 ast::ModuleItemKind::EnumDef(it) => {
161 if let Some(name) = it.name() { 158 if let Some(name) = it.name() {
@@ -163,7 +160,6 @@ impl LoweredModule {
163 let e: ModuleDef = e.into(); 160 let e: ModuleDef = e.into();
164 self.declarations.insert(name.as_name(), PerNs::types(e)); 161 self.declarations.insert(name.as_name(), PerNs::types(e));
165 } 162 }
166 return;
167 } 163 }
168 ast::ModuleItemKind::FnDef(it) => { 164 ast::ModuleItemKind::FnDef(it) => {
169 if let Some(name) = it.name() { 165 if let Some(name) = it.name() {
@@ -171,21 +167,29 @@ impl LoweredModule {
171 self.declarations 167 self.declarations
172 .insert(name.as_name(), PerNs::values(func.into())); 168 .insert(name.as_name(), PerNs::values(func.into()));
173 } 169 }
174 return;
175 } 170 }
176 ast::ModuleItemKind::TraitDef(it) => it.name(), 171 ast::ModuleItemKind::TraitDef(it) => {
177 ast::ModuleItemKind::TypeDef(it) => it.name(), 172 if let Some(name) = it.name() {
173 let t = Trait { id: ctx.to_def(it) };
174 self.declarations
175 .insert(name.as_name(), PerNs::types(t.into()));
176 }
177 }
178 ast::ModuleItemKind::TypeDef(it) => {
179 if let Some(name) = it.name() {
180 let t = Type { id: ctx.to_def(it) };
181 self.declarations
182 .insert(name.as_name(), PerNs::types(t.into()));
183 }
184 }
178 ast::ModuleItemKind::ImplBlock(_) => { 185 ast::ModuleItemKind::ImplBlock(_) => {
179 // impls don't define items 186 // impls don't define items
180 return;
181 } 187 }
182 ast::ModuleItemKind::UseItem(it) => { 188 ast::ModuleItemKind::UseItem(it) => {
183 self.add_use_item(source_map, it); 189 self.add_use_item(source_map, it);
184 return;
185 } 190 }
186 ast::ModuleItemKind::ExternCrateItem(_) => { 191 ast::ModuleItemKind::ExternCrateItem(_) => {
187 // TODO 192 // TODO
188 return;
189 } 193 }
190 ast::ModuleItemKind::ConstDef(it) => { 194 ast::ModuleItemKind::ConstDef(it) => {
191 if let Some(name) = it.name() { 195 if let Some(name) = it.name() {
@@ -193,7 +197,6 @@ impl LoweredModule {
193 self.declarations 197 self.declarations
194 .insert(name.as_name(), PerNs::values(c.into())); 198 .insert(name.as_name(), PerNs::values(c.into()));
195 } 199 }
196 return;
197 } 200 }
198 ast::ModuleItemKind::StaticDef(it) => { 201 ast::ModuleItemKind::StaticDef(it) => {
199 if let Some(name) = it.name() { 202 if let Some(name) = it.name() {
@@ -201,17 +204,11 @@ impl LoweredModule {
201 self.declarations 204 self.declarations
202 .insert(name.as_name(), PerNs::values(s.into())); 205 .insert(name.as_name(), PerNs::values(s.into()));
203 } 206 }
204 return;
205 } 207 }
206 ast::ModuleItemKind::Module(_) => { 208 ast::ModuleItemKind::Module(_) => {
207 // modules are handled separately direclty by nameres 209 // modules are handled separately direclty by nameres
208 return;
209 } 210 }
210 }; 211 };
211 if let Some(name) = name {
212 let def_id = assign_def_id(db, module, file_id, file_items, item);
213 self.declarations.insert(name.as_name(), def_id);
214 }
215 } 212 }
216 213
217 fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) { 214 fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) {
@@ -226,43 +223,3 @@ impl LoweredModule {
226 }) 223 })
227 } 224 }
228} 225}
229
230fn assign_def_id(
231 db: &impl HirDatabase,
232 module: Module,
233 file_id: HirFileId,
234 file_items: &SourceFileItems,
235 item: &ast::ModuleItem,
236) -> PerNs<ModuleDef> {
237 // depending on the item kind, the location can define something in
238 // the values namespace, the types namespace, or both
239 let kind = DefKind::for_syntax_kind(item.syntax().kind());
240 let def_id = kind.map(|k| {
241 let item_id = file_items.id_of_unchecked(item.syntax());
242 let def_loc = DefLoc {
243 kind: k,
244 module,
245 source_item_id: SourceItemId {
246 file_id,
247 item_id: Some(item_id),
248 },
249 };
250 def_loc.id(db).into()
251 });
252 def_id
253}
254
255impl DefKind {
256 fn for_syntax_kind(kind: SyntaxKind) -> PerNs<DefKind> {
257 match kind {
258 SyntaxKind::FN_DEF => unreachable!(),
259 SyntaxKind::STRUCT_DEF => unreachable!(),
260 SyntaxKind::ENUM_DEF => unreachable!(),
261 SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Trait),
262 SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Type),
263 SyntaxKind::CONST_DEF => unreachable!(),
264 SyntaxKind::STATIC_DEF => unreachable!(),
265 _ => PerNs::none(),
266 }
267 }
268}
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index ea8185853..dbe040805 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -145,10 +145,10 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
145 .iter() 145 .iter()
146 .filter_map(|(_, it)| it.clone().take_types()) 146 .filter_map(|(_, it)| it.clone().take_types())
147 .filter_map(|it| match it { 147 .filter_map(|it| match it {
148 ModuleDef::Def(it) => Some(it), 148 ModuleDef::Trait(it) => Some(it),
149 _ => None, 149 _ => None,
150 }) 150 })
151 .filter_map(|it| it.loc(db).source_item_id.file_id.as_macro_call_id()) 151 .filter_map(|it| it.source(db).0.as_macro_call_id())
152 { 152 {
153 if let Some(exp) = db.expand_macro_invocation(macro_call_id) { 153 if let Some(exp) = db.expand_macro_invocation(macro_call_id) {
154 let loc = macro_call_id.loc(db); 154 let loc = macro_call_id.loc(db);
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 6d6150096..3801e498e 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -696,7 +696,9 @@ impl From<ModuleDef> for Option<TypableDef> {
696 ModuleDef::Const(_) 696 ModuleDef::Const(_)
697 | ModuleDef::Static(_) 697 | ModuleDef::Static(_)
698 | ModuleDef::Def(_) 698 | ModuleDef::Def(_)
699 | ModuleDef::Module(_) => return None, 699 | ModuleDef::Module(_)
700 | ModuleDef::Trait(_)
701 | ModuleDef::Type(_) => return None,
700 }; 702 };
701 Some(res) 703 Some(res)
702 } 704 }
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index bd5484516..e72586e2e 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -40,12 +40,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
40 .add_to(acc) 40 .add_to(acc)
41 }); 41 });
42 } 42 }
43 hir::ModuleDef::Function(_) 43 _ => return,
44 | hir::ModuleDef::Struct(_)
45 | hir::ModuleDef::Def(_)
46 | hir::ModuleDef::Const(_)
47 | hir::ModuleDef::Static(_)
48 | hir::ModuleDef::EnumVariant(_) => return,
49 }; 44 };
50} 45}
51 46
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 2f8ec41d2..4e679281c 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -225,11 +225,9 @@ impl Builder {
225 hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), 225 hir::ModuleDef::EnumVariant(it) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)),
226 hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)), 226 hir::ModuleDef::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
227 hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)), 227 hir::ModuleDef::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)),
228 hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) { 228 hir::ModuleDef::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)),
229 hir::Def::Trait(it) => (CompletionItemKind::Trait, it.docs(ctx.db)), 229 hir::ModuleDef::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
230 hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), 230 hir::ModuleDef::Def(_) => return self,
231 _ => return self,
232 },
233 }; 231 };
234 self.kind = Some(kind); 232 self.kind = Some(kind);
235 self.documentation = docs; 233 self.documentation = docs;
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 8406fee31..2e11d2de3 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 SyntaxNode, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
5}; 5};
6use hir::{Def, ModuleSource}; 6use hir::{ModuleSource};
7 7
8use crate::{FileSymbol, db::RootDatabase}; 8use crate::{FileSymbol, db::RootDatabase};
9 9
@@ -106,63 +106,60 @@ impl NavigationTarget {
106 db: &RootDatabase, 106 db: &RootDatabase,
107 module_def: hir::ModuleDef, 107 module_def: hir::ModuleDef,
108 ) -> Option<NavigationTarget> { 108 ) -> Option<NavigationTarget> {
109 let def = match module_def { 109 match module_def {
110 hir::ModuleDef::Def(def_id) => def_id.resolve(db), 110 hir::ModuleDef::Def(_) => return None,
111 hir::ModuleDef::Module(module) => { 111 hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)),
112 return Some(NavigationTarget::from_module(db, module)); 112 hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)),
113 }
114 hir::ModuleDef::Function(func) => {
115 return Some(NavigationTarget::from_function(db, func));
116 }
117 hir::ModuleDef::Struct(s) => { 113 hir::ModuleDef::Struct(s) => {
118 let (file_id, node) = s.source(db); 114 let (file_id, node) = s.source(db);
119 return Some(NavigationTarget::from_named( 115 Some(NavigationTarget::from_named(
120 file_id.original_file(db), 116 file_id.original_file(db),
121 &*node, 117 &*node,
122 )); 118 ))
123 } 119 }
124 hir::ModuleDef::Const(s) => { 120 hir::ModuleDef::Const(s) => {
125 let (file_id, node) = s.source(db); 121 let (file_id, node) = s.source(db);
126 return Some(NavigationTarget::from_named( 122 Some(NavigationTarget::from_named(
127 file_id.original_file(db), 123 file_id.original_file(db),
128 &*node, 124 &*node,
129 )); 125 ))
130 } 126 }
131 hir::ModuleDef::Static(s) => { 127 hir::ModuleDef::Static(s) => {
132 let (file_id, node) = s.source(db); 128 let (file_id, node) = s.source(db);
133 return Some(NavigationTarget::from_named( 129 Some(NavigationTarget::from_named(
134 file_id.original_file(db), 130 file_id.original_file(db),
135 &*node, 131 &*node,
136 )); 132 ))
137 } 133 }
138 hir::ModuleDef::Enum(e) => { 134 hir::ModuleDef::Enum(e) => {
139 let (file_id, node) = e.source(db); 135 let (file_id, node) = e.source(db);
140 return Some(NavigationTarget::from_named( 136 Some(NavigationTarget::from_named(
141 file_id.original_file(db), 137 file_id.original_file(db),
142 &*node, 138 &*node,
143 )); 139 ))
144 } 140 }
145 hir::ModuleDef::EnumVariant(var) => { 141 hir::ModuleDef::EnumVariant(var) => {
146 let (file_id, node) = var.source(db); 142 let (file_id, node) = var.source(db);
147 return Some(NavigationTarget::from_named( 143 Some(NavigationTarget::from_named(
148 file_id.original_file(db), 144 file_id.original_file(db),
149 &*node, 145 &*node,
150 )); 146 ))
151 } 147 }
152 }; 148 hir::ModuleDef::Trait(e) => {
153 149 let (file_id, node) = e.source(db);
154 let res = match def { 150 Some(NavigationTarget::from_named(
155 Def::Trait(f) => { 151 file_id.original_file(db),
156 let (file_id, node) = f.source(db); 152 &*node,
157 NavigationTarget::from_named(file_id.original_file(db), &*node) 153 ))
158 } 154 }
159 Def::Type(f) => { 155 hir::ModuleDef::Type(e) => {
160 let (file_id, node) = f.source(db); 156 let (file_id, node) = e.source(db);
161 NavigationTarget::from_named(file_id.original_file(db), &*node) 157 Some(NavigationTarget::from_named(
158 file_id.original_file(db),
159 &*node,
160 ))
162 } 161 }
163 Def::Item => return None, 162 }
164 };
165 Some(res)
166 } 163 }
167 164
168 #[cfg(test)] 165 #[cfg(test)]
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index ac6c8a835..a207f8429 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -3229,6 +3229,7 @@ impl ast::VisibilityOwner for TraitDef {}
3229impl ast::NameOwner for TraitDef {} 3229impl ast::NameOwner for TraitDef {}
3230impl ast::AttrsOwner for TraitDef {} 3230impl ast::AttrsOwner for TraitDef {}
3231impl ast::DocCommentsOwner for TraitDef {} 3231impl ast::DocCommentsOwner for TraitDef {}
3232impl ast::TypeParamsOwner for TraitDef {}
3232impl TraitDef {} 3233impl TraitDef {}
3233 3234
3234// TrueKw 3235// TrueKw
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index c5297e46d..dedefea59 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -280,7 +280,7 @@ Grammar(
280 ], options: [["variant_list", "EnumVariantList"]] ), 280 ], options: [["variant_list", "EnumVariantList"]] ),
281 "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ), 281 "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
282 "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner"], options: ["Expr"] ), 282 "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner"], options: ["Expr"] ),
283 "TraitDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner"] ), 283 "TraitDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner"] ),
284 "Module": ( 284 "Module": (
285 traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ], 285 traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
286 options: [ "ItemList" ] 286 options: [ "ItemList" ]
@@ -489,7 +489,7 @@ Grammar(
489 ), 489 ),
490 490
491 "RefPat": ( options: [ "Pat" ]), 491 "RefPat": ( options: [ "Pat" ]),
492 "BindPat": ( 492 "BindPat": (
493 options: [ "Pat" ], 493 options: [ "Pat" ],
494 traits: ["NameOwner"] 494 traits: ["NameOwner"]
495 ), 495 ),