diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 55 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 6 |
4 files changed, 47 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index d77ccb272..78a532bdd 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -6,8 +6,7 @@ pub mod scope; | |||
6 | use std::{ops::Index, sync::Arc}; | 6 | use std::{ops::Index, sync::Arc}; |
7 | 7 | ||
8 | use hir_expand::{ | 8 | use hir_expand::{ |
9 | either::Either, hygiene::Hygiene, AstId, HirFileId, MacroCallLoc, MacroDefId, MacroFileKind, | 9 | either::Either, hygiene::Hygiene, AstId, HirFileId, MacroDefId, MacroFileKind, Source, |
10 | Source, | ||
11 | }; | 10 | }; |
12 | use ra_arena::{map::ArenaMap, Arena}; | 11 | use ra_arena::{map::ArenaMap, Arena}; |
13 | use ra_syntax::{ast, AstNode, AstPtr}; | 12 | use ra_syntax::{ast, AstNode, AstPtr}; |
@@ -47,7 +46,7 @@ impl Expander { | |||
47 | 46 | ||
48 | if let Some(path) = macro_call.path().and_then(|path| self.parse_path(path)) { | 47 | if let Some(path) = macro_call.path().and_then(|path| self.parse_path(path)) { |
49 | if let Some(def) = self.resolve_path_as_macro(db, &path) { | 48 | if let Some(def) = self.resolve_path_as_macro(db, &path) { |
50 | let call_id = db.intern_macro(MacroCallLoc { def, ast_id }); | 49 | let call_id = def.as_call_id(db, ast_id); |
51 | let file_id = call_id.as_file(MacroFileKind::Expr); | 50 | let file_id = call_id.as_file(MacroFileKind::Expr); |
52 | if let Some(node) = db.parse_or_expand(file_id) { | 51 | if let Some(node) = db.parse_or_expand(file_id) { |
53 | if let Some(expr) = ast::Expr::cast(node) { | 52 | if let Some(expr) = ast::Expr::cast(node) { |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 68bea34df..813099a05 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -87,7 +87,7 @@ impl TypeAliasData { | |||
87 | #[derive(Debug, Clone, PartialEq, Eq)] | 87 | #[derive(Debug, Clone, PartialEq, Eq)] |
88 | pub struct TraitData { | 88 | pub struct TraitData { |
89 | pub name: Option<Name>, | 89 | pub name: Option<Name>, |
90 | pub items: Vec<AssocItemId>, | 90 | pub items: Vec<(Name, AssocItemId)>, |
91 | pub auto: bool, | 91 | pub auto: bool, |
92 | } | 92 | } |
93 | 93 | ||
@@ -97,28 +97,42 @@ impl TraitData { | |||
97 | let name = src.value.name().map(|n| n.as_name()); | 97 | let name = src.value.name().map(|n| n.as_name()); |
98 | let auto = src.value.is_auto(); | 98 | let auto = src.value.is_auto(); |
99 | let ast_id_map = db.ast_id_map(src.file_id); | 99 | let ast_id_map = db.ast_id_map(src.file_id); |
100 | |||
101 | let container = ContainerId::TraitId(tr); | ||
100 | let items = if let Some(item_list) = src.value.item_list() { | 102 | let items = if let Some(item_list) = src.value.item_list() { |
101 | item_list | 103 | item_list |
102 | .impl_items() | 104 | .impl_items() |
103 | .map(|item_node| match item_node { | 105 | .map(|item_node| match item_node { |
104 | ast::ImplItem::FnDef(it) => FunctionLoc { | 106 | ast::ImplItem::FnDef(it) => { |
105 | container: ContainerId::TraitId(tr), | 107 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); |
106 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 108 | let def = FunctionLoc { |
109 | container, | ||
110 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | ||
111 | } | ||
112 | .intern(db) | ||
113 | .into(); | ||
114 | (name, def) | ||
107 | } | 115 | } |
108 | .intern(db) | 116 | ast::ImplItem::ConstDef(it) => { |
109 | .into(), | 117 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); |
110 | ast::ImplItem::ConstDef(it) => ConstLoc { | 118 | let def = ConstLoc { |
111 | container: ContainerId::TraitId(tr), | 119 | container, |
112 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 120 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), |
121 | } | ||
122 | .intern(db) | ||
123 | .into(); | ||
124 | (name, def) | ||
113 | } | 125 | } |
114 | .intern(db) | 126 | ast::ImplItem::TypeAliasDef(it) => { |
115 | .into(), | 127 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); |
116 | ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { | 128 | let def = TypeAliasLoc { |
117 | container: ContainerId::TraitId(tr), | 129 | container, |
118 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 130 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), |
131 | } | ||
132 | .intern(db) | ||
133 | .into(); | ||
134 | (name, def) | ||
119 | } | 135 | } |
120 | .intern(db) | ||
121 | .into(), | ||
122 | }) | 136 | }) |
123 | .collect() | 137 | .collect() |
124 | } else { | 138 | } else { |
@@ -128,11 +142,18 @@ impl TraitData { | |||
128 | } | 142 | } |
129 | 143 | ||
130 | pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ { | 144 | pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ { |
131 | self.items.iter().filter_map(|item| match item { | 145 | self.items.iter().filter_map(|(_name, item)| match item { |
132 | AssocItemId::TypeAliasId(t) => Some(*t), | 146 | AssocItemId::TypeAliasId(t) => Some(*t), |
133 | _ => None, | 147 | _ => None, |
134 | }) | 148 | }) |
135 | } | 149 | } |
150 | |||
151 | pub fn associated_type_by_name(&self, name: &Name) -> Option<TypeAliasId> { | ||
152 | self.items.iter().find_map(|(item_name, item)| match item { | ||
153 | AssocItemId::TypeAliasId(t) if item_name == name => Some(*t), | ||
154 | _ => None, | ||
155 | }) | ||
156 | } | ||
136 | } | 157 | } |
137 | 158 | ||
138 | #[derive(Debug, Clone, PartialEq, Eq)] | 159 | #[derive(Debug, Clone, PartialEq, Eq)] |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 4ff6f72cf..ea3abfdae 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | use hir_expand::{ | 6 | use hir_expand::{ |
7 | builtin_macro::find_builtin_macro, | 7 | builtin_macro::find_builtin_macro, |
8 | name::{self, AsName, Name}, | 8 | name::{self, AsName, Name}, |
9 | HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind, | 9 | HirFileId, MacroCallId, MacroDefId, MacroDefKind, MacroFileKind, |
10 | }; | 10 | }; |
11 | use ra_cfg::CfgOptions; | 11 | use ra_cfg::CfgOptions; |
12 | use ra_db::{CrateId, FileId}; | 12 | use ra_db::{CrateId, FileId}; |
@@ -480,7 +480,7 @@ where | |||
480 | ); | 480 | ); |
481 | 481 | ||
482 | if let Some(def) = resolved_res.resolved_def.take_macros() { | 482 | if let Some(def) = resolved_res.resolved_def.take_macros() { |
483 | let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id }); | 483 | let call_id = def.as_call_id(self.db, *ast_id); |
484 | resolved.push((*module_id, call_id, def)); | 484 | resolved.push((*module_id, call_id, def)); |
485 | res = ReachedFixedPoint::No; | 485 | res = ReachedFixedPoint::No; |
486 | return false; | 486 | return false; |
@@ -773,8 +773,7 @@ where | |||
773 | if let Some(macro_def) = mac.path.as_ident().and_then(|name| { | 773 | if let Some(macro_def) = mac.path.as_ident().and_then(|name| { |
774 | self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) | 774 | self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) |
775 | }) { | 775 | }) { |
776 | let macro_call_id = | 776 | let macro_call_id = macro_def.as_call_id(self.def_collector.db, ast_id); |
777 | self.def_collector.db.intern_macro(MacroCallLoc { def: macro_def, ast_id }); | ||
778 | 777 | ||
779 | self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, macro_def); | 778 | self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, macro_def); |
780 | return; | 779 | return; |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 95b3c926d..5155365cc 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -61,6 +61,8 @@ pub enum TypeNs { | |||
61 | GenericParam(u32), | 61 | GenericParam(u32), |
62 | AdtId(AdtId), | 62 | AdtId(AdtId), |
63 | AdtSelfType(AdtId), | 63 | AdtSelfType(AdtId), |
64 | // Yup, enum variants are added to the types ns, but any usage of variant as | ||
65 | // type is an error. | ||
64 | EnumVariantId(EnumVariantId), | 66 | EnumVariantId(EnumVariantId), |
65 | TypeAliasId(TypeAliasId), | 67 | TypeAliasId(TypeAliasId), |
66 | BuiltinType(BuiltinType), | 68 | BuiltinType(BuiltinType), |
@@ -482,7 +484,7 @@ impl Resolver { | |||
482 | } | 484 | } |
483 | } | 485 | } |
484 | 486 | ||
485 | pub trait HasResolver { | 487 | pub trait HasResolver: Copy { |
486 | /// Builds a resolver for type references inside this def. | 488 | /// Builds a resolver for type references inside this def. |
487 | fn resolver(self, db: &impl DefDatabase) -> Resolver; | 489 | fn resolver(self, db: &impl DefDatabase) -> Resolver; |
488 | } | 490 | } |
@@ -500,7 +502,7 @@ impl HasResolver for TraitId { | |||
500 | } | 502 | } |
501 | } | 503 | } |
502 | 504 | ||
503 | impl<T: Into<AdtId>> HasResolver for T { | 505 | impl<T: Into<AdtId> + Copy> HasResolver for T { |
504 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 506 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
505 | let def = self.into(); | 507 | let def = self.into(); |
506 | def.module(db) | 508 | def.module(db) |