diff options
Diffstat (limited to 'crates/ra_hir_def/src/data.rs')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index b8fbf0ed4..ccb682f9a 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -9,18 +9,19 @@ use hir_expand::{ | |||
9 | }; | 9 | }; |
10 | use ra_prof::profile; | 10 | use ra_prof::profile; |
11 | use ra_syntax::ast::{ | 11 | use ra_syntax::ast::{ |
12 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, | 12 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, TypeBoundsOwner, |
13 | VisibilityOwner, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | use crate::{ | 16 | use crate::{ |
16 | attr::Attrs, | 17 | attr::Attrs, |
17 | db::DefDatabase, | 18 | db::DefDatabase, |
18 | path::{path, GenericArgs, Path}, | 19 | path::{path, AssociatedTypeBinding, GenericArgs, Path}, |
19 | src::HasSource, | 20 | src::HasSource, |
20 | type_ref::{Mutability, TypeBound, TypeRef}, | 21 | type_ref::{Mutability, TypeBound, TypeRef}, |
21 | visibility::RawVisibility, | 22 | visibility::RawVisibility, |
22 | AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, | 23 | AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, |
23 | ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, | 24 | ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
24 | }; | 25 | }; |
25 | 26 | ||
26 | #[derive(Debug, Clone, PartialEq, Eq)] | 27 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -95,7 +96,11 @@ fn desugar_future_path(orig: TypeRef) -> Path { | |||
95 | let path = path![std::future::Future]; | 96 | let path = path![std::future::Future]; |
96 | let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect(); | 97 | let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect(); |
97 | let mut last = GenericArgs::empty(); | 98 | let mut last = GenericArgs::empty(); |
98 | last.bindings.push((name![Output], orig)); | 99 | last.bindings.push(AssociatedTypeBinding { |
100 | name: name![Output], | ||
101 | type_ref: Some(orig), | ||
102 | bounds: Vec::new(), | ||
103 | }); | ||
99 | generic_args.push(Some(Arc::new(last))); | 104 | generic_args.push(Some(Arc::new(last))); |
100 | 105 | ||
101 | Path::from_known_path(path, generic_args) | 106 | Path::from_known_path(path, generic_args) |
@@ -106,6 +111,7 @@ pub struct TypeAliasData { | |||
106 | pub name: Name, | 111 | pub name: Name, |
107 | pub type_ref: Option<TypeRef>, | 112 | pub type_ref: Option<TypeRef>, |
108 | pub visibility: RawVisibility, | 113 | pub visibility: RawVisibility, |
114 | pub bounds: Vec<TypeBound>, | ||
109 | } | 115 | } |
110 | 116 | ||
111 | impl TypeAliasData { | 117 | impl TypeAliasData { |
@@ -118,9 +124,17 @@ impl TypeAliasData { | |||
118 | let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); | 124 | let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); |
119 | let type_ref = node.value.type_ref().map(TypeRef::from_ast); | 125 | let type_ref = node.value.type_ref().map(TypeRef::from_ast); |
120 | let vis_default = RawVisibility::default_for_container(loc.container); | 126 | let vis_default = RawVisibility::default_for_container(loc.container); |
121 | let visibility = | 127 | let visibility = RawVisibility::from_ast_with_default( |
122 | RawVisibility::from_ast_with_default(db, vis_default, node.map(|n| n.visibility())); | 128 | db, |
123 | Arc::new(TypeAliasData { name, type_ref, visibility }) | 129 | vis_default, |
130 | node.as_ref().map(|n| n.visibility()), | ||
131 | ); | ||
132 | let bounds = if let Some(bound_list) = node.value.type_bound_list() { | ||
133 | bound_list.bounds().map(TypeBound::from_ast).collect() | ||
134 | } else { | ||
135 | Vec::new() | ||
136 | }; | ||
137 | Arc::new(TypeAliasData { name, type_ref, visibility, bounds }) | ||
124 | } | 138 | } |
125 | } | 139 | } |
126 | 140 | ||
@@ -218,10 +232,17 @@ impl ImplData { | |||
218 | let mut items = Vec::new(); | 232 | let mut items = Vec::new(); |
219 | 233 | ||
220 | if let Some(item_list) = src.value.item_list() { | 234 | if let Some(item_list) = src.value.item_list() { |
221 | items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); | 235 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); |
236 | items.extend(collect_impl_items( | ||
237 | db, | ||
238 | &mut expander, | ||
239 | item_list.impl_items(), | ||
240 | src.file_id, | ||
241 | id, | ||
242 | )); | ||
222 | items.extend(collect_impl_items_in_macros( | 243 | items.extend(collect_impl_items_in_macros( |
223 | db, | 244 | db, |
224 | module_id, | 245 | &mut expander, |
225 | &src.with_value(item_list), | 246 | &src.with_value(item_list), |
226 | id, | 247 | id, |
227 | )); | 248 | )); |
@@ -268,18 +289,17 @@ impl ConstData { | |||
268 | 289 | ||
269 | fn collect_impl_items_in_macros( | 290 | fn collect_impl_items_in_macros( |
270 | db: &dyn DefDatabase, | 291 | db: &dyn DefDatabase, |
271 | module_id: ModuleId, | 292 | expander: &mut Expander, |
272 | impl_def: &InFile<ast::ItemList>, | 293 | impl_def: &InFile<ast::ItemList>, |
273 | id: ImplId, | 294 | id: ImplId, |
274 | ) -> Vec<AssocItemId> { | 295 | ) -> Vec<AssocItemId> { |
275 | let mut expander = Expander::new(db, impl_def.file_id, module_id); | ||
276 | let mut res = Vec::new(); | 296 | let mut res = Vec::new(); |
277 | 297 | ||
278 | // We set a limit to protect against infinite recursion | 298 | // We set a limit to protect against infinite recursion |
279 | let limit = 100; | 299 | let limit = 100; |
280 | 300 | ||
281 | for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) { | 301 | for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) { |
282 | res.extend(collect_impl_items_in_macro(db, &mut expander, m, id, limit)) | 302 | res.extend(collect_impl_items_in_macro(db, expander, m, id, limit)) |
283 | } | 303 | } |
284 | 304 | ||
285 | res | 305 | res |
@@ -300,6 +320,7 @@ fn collect_impl_items_in_macro( | |||
300 | let items: InFile<ast::MacroItems> = expander.to_source(items); | 320 | let items: InFile<ast::MacroItems> = expander.to_source(items); |
301 | let mut res = collect_impl_items( | 321 | let mut res = collect_impl_items( |
302 | db, | 322 | db, |
323 | expander, | ||
303 | items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), | 324 | items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), |
304 | items.file_id, | 325 | items.file_id, |
305 | id, | 326 | id, |
@@ -319,32 +340,26 @@ fn collect_impl_items_in_macro( | |||
319 | 340 | ||
320 | fn collect_impl_items( | 341 | fn collect_impl_items( |
321 | db: &dyn DefDatabase, | 342 | db: &dyn DefDatabase, |
343 | expander: &mut Expander, | ||
322 | impl_items: impl Iterator<Item = ImplItem>, | 344 | impl_items: impl Iterator<Item = ImplItem>, |
323 | file_id: crate::HirFileId, | 345 | file_id: crate::HirFileId, |
324 | id: ImplId, | 346 | id: ImplId, |
325 | ) -> Vec<AssocItemId> { | 347 | ) -> Vec<AssocItemId> { |
326 | let items = db.ast_id_map(file_id); | 348 | let items = db.ast_id_map(file_id); |
327 | let crate_graph = db.crate_graph(); | ||
328 | let module_id = id.lookup(db).container.module(db); | ||
329 | 349 | ||
330 | impl_items | 350 | impl_items |
331 | .filter_map(|item_node| match item_node { | 351 | .filter_map(|item_node| match item_node { |
332 | ast::ImplItem::FnDef(it) => { | 352 | ast::ImplItem::FnDef(it) => { |
353 | let attrs = expander.parse_attrs(&it); | ||
354 | if !expander.is_cfg_enabled(&attrs) { | ||
355 | return None; | ||
356 | } | ||
333 | let def = FunctionLoc { | 357 | let def = FunctionLoc { |
334 | container: AssocContainerId::ImplId(id), | 358 | container: AssocContainerId::ImplId(id), |
335 | ast_id: AstId::new(file_id, items.ast_id(&it)), | 359 | ast_id: AstId::new(file_id, items.ast_id(&it)), |
336 | } | 360 | } |
337 | .intern(db); | 361 | .intern(db); |
338 | 362 | Some(def.into()) | |
339 | if !db | ||
340 | .function_data(def) | ||
341 | .attrs | ||
342 | .is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) | ||
343 | { | ||
344 | None | ||
345 | } else { | ||
346 | Some(def.into()) | ||
347 | } | ||
348 | } | 363 | } |
349 | ast::ImplItem::ConstDef(it) => { | 364 | ast::ImplItem::ConstDef(it) => { |
350 | let def = ConstLoc { | 365 | let def = ConstLoc { |