diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 37 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower/lower_use.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/visibility.rs | 4 |
9 files changed, 55 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index de07fc952..7fc4cd76e 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -54,6 +54,7 @@ pub struct StructFieldData { | |||
54 | impl StructData { | 54 | impl StructData { |
55 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { | 55 | pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { |
56 | let src = id.lookup(db).source(db); | 56 | let src = id.lookup(db).source(db); |
57 | |||
57 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 58 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
58 | let variant_data = VariantData::new(db, src.map(|s| s.kind())); | 59 | let variant_data = VariantData::new(db, src.map(|s| s.kind())); |
59 | let variant_data = Arc::new(variant_data); | 60 | let variant_data = Arc::new(variant_data); |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 8d4b8b0f0..c4a5ec59c 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -482,14 +482,16 @@ impl ExprCollector<'_> { | |||
482 | self.collect_block_items(&block); | 482 | self.collect_block_items(&block); |
483 | let statements = block | 483 | let statements = block |
484 | .statements() | 484 | .statements() |
485 | .map(|s| match s { | 485 | .filter_map(|s| match s { |
486 | ast::Stmt::LetStmt(stmt) => { | 486 | ast::Stmt::LetStmt(stmt) => { |
487 | let pat = self.collect_pat_opt(stmt.pat()); | 487 | let pat = self.collect_pat_opt(stmt.pat()); |
488 | let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); | 488 | let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); |
489 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 489 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
490 | Statement::Let { pat, type_ref, initializer } | 490 | Some(Statement::Let { pat, type_ref, initializer }) |
491 | } | ||
492 | ast::Stmt::ExprStmt(stmt) => { | ||
493 | Some(Statement::Expr(self.collect_expr_opt(stmt.expr()))) | ||
491 | } | 494 | } |
492 | ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), | ||
493 | }) | 495 | }) |
494 | .collect(); | 496 | .collect(); |
495 | let tail = block.expr().map(|e| self.collect_expr(e)); | 497 | let tail = block.expr().map(|e| self.collect_expr(e)); |
@@ -541,6 +543,7 @@ impl ExprCollector<'_> { | |||
541 | let ast_id = self.expander.ast_id(&def); | 543 | let ast_id = self.expander.ast_id(&def); |
542 | (TraitLoc { container, ast_id }.intern(self.db).into(), def.name()) | 544 | (TraitLoc { container, ast_id }.intern(self.db).into(), def.name()) |
543 | } | 545 | } |
546 | ast::ModuleItem::ExternBlock(_) => continue, // FIXME: collect from extern blocks | ||
544 | ast::ModuleItem::ImplDef(_) | 547 | ast::ModuleItem::ImplDef(_) |
545 | | ast::ModuleItem::UseItem(_) | 548 | | ast::ModuleItem::UseItem(_) |
546 | | ast::ModuleItem::ExternCrateItem(_) | 549 | | ast::ModuleItem::ExternCrateItem(_) |
@@ -569,7 +572,10 @@ impl ExprCollector<'_> { | |||
569 | let pattern = match &pat { | 572 | let pattern = match &pat { |
570 | ast::Pat::BindPat(bp) => { | 573 | ast::Pat::BindPat(bp) => { |
571 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 574 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
572 | let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); | 575 | let annotation = BindingAnnotation::new( |
576 | bp.mut_kw_token().is_some(), | ||
577 | bp.ref_kw_token().is_some(), | ||
578 | ); | ||
573 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); | 579 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); |
574 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { | 580 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { |
575 | // This could also be a single-segment path pattern. To | 581 | // This could also be a single-segment path pattern. To |
@@ -610,7 +616,7 @@ impl ExprCollector<'_> { | |||
610 | } | 616 | } |
611 | ast::Pat::RefPat(p) => { | 617 | ast::Pat::RefPat(p) => { |
612 | let pat = self.collect_pat_opt(p.pat()); | 618 | let pat = self.collect_pat_opt(p.pat()); |
613 | let mutability = Mutability::from_mutable(p.is_mut()); | 619 | let mutability = Mutability::from_mutable(p.mut_kw_token().is_some()); |
614 | Pat::Ref { pat, mutability } | 620 | Pat::Ref { pat, mutability } |
615 | } | 621 | } |
616 | ast::Pat::PathPat(p) => { | 622 | ast::Pat::PathPat(p) => { |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 04bd4a305..689bb6c5c 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -3,15 +3,18 @@ | |||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::{ | 5 | use hir_expand::{ |
6 | hygiene::Hygiene, | ||
6 | name::{name, AsName, Name}, | 7 | name::{name, AsName, Name}, |
7 | AstId, InFile, | 8 | AstId, InFile, |
8 | }; | 9 | }; |
10 | use ra_cfg::CfgOptions; | ||
9 | use ra_prof::profile; | 11 | use ra_prof::profile; |
10 | use ra_syntax::ast::{ | 12 | use ra_syntax::ast::{ |
11 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, | 13 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, |
12 | }; | 14 | }; |
13 | 15 | ||
14 | use crate::{ | 16 | use crate::{ |
17 | attr::Attrs, | ||
15 | db::DefDatabase, | 18 | db::DefDatabase, |
16 | path::{path, GenericArgs, Path}, | 19 | path::{path, GenericArgs, Path}, |
17 | src::HasSource, | 20 | src::HasSource, |
@@ -26,6 +29,7 @@ pub struct FunctionData { | |||
26 | pub name: Name, | 29 | pub name: Name, |
27 | pub params: Vec<TypeRef>, | 30 | pub params: Vec<TypeRef>, |
28 | pub ret_type: TypeRef, | 31 | pub ret_type: TypeRef, |
32 | pub attrs: Attrs, | ||
29 | /// True if the first param is `self`. This is relevant to decide whether this | 33 | /// True if the first param is `self`. This is relevant to decide whether this |
30 | /// can be called as a method. | 34 | /// can be called as a method. |
31 | pub has_self_param: bool, | 35 | pub has_self_param: bool, |
@@ -63,13 +67,15 @@ impl FunctionData { | |||
63 | params.push(type_ref); | 67 | params.push(type_ref); |
64 | } | 68 | } |
65 | } | 69 | } |
70 | let attrs = Attrs::new(&src.value, &Hygiene::new(db.upcast(), src.file_id)); | ||
71 | |||
66 | let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) { | 72 | let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) { |
67 | TypeRef::from_ast(type_ref) | 73 | TypeRef::from_ast(type_ref) |
68 | } else { | 74 | } else { |
69 | TypeRef::unit() | 75 | TypeRef::unit() |
70 | }; | 76 | }; |
71 | 77 | ||
72 | let ret_type = if src.value.is_async() { | 78 | let ret_type = if src.value.async_kw_token().is_some() { |
73 | let future_impl = desugar_future_path(ret_type); | 79 | let future_impl = desugar_future_path(ret_type); |
74 | let ty_bound = TypeBound::Path(future_impl); | 80 | let ty_bound = TypeBound::Path(future_impl); |
75 | TypeRef::ImplTrait(vec![ty_bound]) | 81 | TypeRef::ImplTrait(vec![ty_bound]) |
@@ -81,7 +87,7 @@ impl FunctionData { | |||
81 | let visibility = | 87 | let visibility = |
82 | RawVisibility::from_ast_with_default(db, vis_default, src.map(|s| s.visibility())); | 88 | RawVisibility::from_ast_with_default(db, vis_default, src.map(|s| s.visibility())); |
83 | 89 | ||
84 | let sig = FunctionData { name, params, ret_type, has_self_param, visibility }; | 90 | let sig = FunctionData { name, params, ret_type, has_self_param, visibility, attrs }; |
85 | Arc::new(sig) | 91 | Arc::new(sig) |
86 | } | 92 | } |
87 | } | 93 | } |
@@ -130,7 +136,7 @@ impl TraitData { | |||
130 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { | 136 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { |
131 | let src = tr.lookup(db).source(db); | 137 | let src = tr.lookup(db).source(db); |
132 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 138 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
133 | let auto = src.value.is_auto(); | 139 | let auto = src.value.auto_kw_token().is_some(); |
134 | let ast_id_map = db.ast_id_map(src.file_id); | 140 | let ast_id_map = db.ast_id_map(src.file_id); |
135 | 141 | ||
136 | let container = AssocContainerId::TraitId(tr); | 142 | let container = AssocContainerId::TraitId(tr); |
@@ -207,10 +213,11 @@ impl ImplData { | |||
207 | 213 | ||
208 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); | 214 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); |
209 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); | 215 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); |
210 | let is_negative = src.value.is_negative(); | 216 | let is_negative = src.value.excl_token().is_some(); |
211 | let module_id = impl_loc.container.module(db); | 217 | let module_id = impl_loc.container.module(db); |
212 | 218 | ||
213 | let mut items = Vec::new(); | 219 | let mut items = Vec::new(); |
220 | |||
214 | if let Some(item_list) = src.value.item_list() { | 221 | if let Some(item_list) = src.value.item_list() { |
215 | items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); | 222 | items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); |
216 | items.extend(collect_impl_items_in_macros( | 223 | items.extend(collect_impl_items_in_macros( |
@@ -311,6 +318,10 @@ fn collect_impl_items_in_macro( | |||
311 | } | 318 | } |
312 | } | 319 | } |
313 | 320 | ||
321 | fn is_cfg_enabled(cfg_options: &CfgOptions, attrs: &Attrs) -> bool { | ||
322 | attrs.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false)) | ||
323 | } | ||
324 | |||
314 | fn collect_impl_items( | 325 | fn collect_impl_items( |
315 | db: &dyn DefDatabase, | 326 | db: &dyn DefDatabase, |
316 | impl_items: impl Iterator<Item = ImplItem>, | 327 | impl_items: impl Iterator<Item = ImplItem>, |
@@ -318,16 +329,26 @@ fn collect_impl_items( | |||
318 | id: ImplId, | 329 | id: ImplId, |
319 | ) -> Vec<AssocItemId> { | 330 | ) -> Vec<AssocItemId> { |
320 | let items = db.ast_id_map(file_id); | 331 | let items = db.ast_id_map(file_id); |
332 | let crate_graph = db.crate_graph(); | ||
333 | let module_id = id.lookup(db).container.module(db); | ||
321 | 334 | ||
322 | impl_items | 335 | impl_items |
323 | .map(|item_node| match item_node { | 336 | .filter_map(|item_node| match item_node { |
324 | ast::ImplItem::FnDef(it) => { | 337 | ast::ImplItem::FnDef(it) => { |
325 | let def = FunctionLoc { | 338 | let def = FunctionLoc { |
326 | container: AssocContainerId::ImplId(id), | 339 | container: AssocContainerId::ImplId(id), |
327 | ast_id: AstId::new(file_id, items.ast_id(&it)), | 340 | ast_id: AstId::new(file_id, items.ast_id(&it)), |
328 | } | 341 | } |
329 | .intern(db); | 342 | .intern(db); |
330 | def.into() | 343 | |
344 | if !is_cfg_enabled( | ||
345 | &crate_graph[module_id.krate].cfg_options, | ||
346 | &db.function_data(def).attrs, | ||
347 | ) { | ||
348 | None | ||
349 | } else { | ||
350 | Some(def.into()) | ||
351 | } | ||
331 | } | 352 | } |
332 | ast::ImplItem::ConstDef(it) => { | 353 | ast::ImplItem::ConstDef(it) => { |
333 | let def = ConstLoc { | 354 | let def = ConstLoc { |
@@ -335,7 +356,7 @@ fn collect_impl_items( | |||
335 | ast_id: AstId::new(file_id, items.ast_id(&it)), | 356 | ast_id: AstId::new(file_id, items.ast_id(&it)), |
336 | } | 357 | } |
337 | .intern(db); | 358 | .intern(db); |
338 | def.into() | 359 | Some(def.into()) |
339 | } | 360 | } |
340 | ast::ImplItem::TypeAliasDef(it) => { | 361 | ast::ImplItem::TypeAliasDef(it) => { |
341 | let def = TypeAliasLoc { | 362 | let def = TypeAliasLoc { |
@@ -343,7 +364,7 @@ fn collect_impl_items( | |||
343 | ast_id: AstId::new(file_id, items.ast_id(&it)), | 364 | ast_id: AstId::new(file_id, items.ast_id(&it)), |
344 | } | 365 | } |
345 | .intern(db); | 366 | .intern(db); |
346 | def.into() | 367 | Some(def.into()) |
347 | } | 368 | } |
348 | }) | 369 | }) |
349 | .collect() | 370 | .collect() |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index b687ce2b2..d850244c4 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -194,7 +194,7 @@ impl GenericParams { | |||
194 | } | 194 | } |
195 | 195 | ||
196 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { | 196 | fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { |
197 | if bound.has_question_mark() { | 197 | if bound.question_token().is_some() { |
198 | // FIXME: remove this bound | 198 | // FIXME: remove this bound |
199 | return; | 199 | return; |
200 | } | 200 | } |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 8f190e7f9..e72ba52cf 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -266,6 +266,10 @@ impl RawItemsCollector { | |||
266 | self.add_macro(current_module, it); | 266 | self.add_macro(current_module, it); |
267 | return; | 267 | return; |
268 | } | 268 | } |
269 | ast::ModuleItem::ExternBlock(_) => { | ||
270 | // FIXME: add extern block | ||
271 | return; | ||
272 | } | ||
269 | }; | 273 | }; |
270 | if let Some(name) = name { | 274 | if let Some(name) = name { |
271 | let name = name.as_name(); | 275 | let name = name.as_name(); |
@@ -283,7 +287,7 @@ impl RawItemsCollector { | |||
283 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); | 287 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); |
284 | 288 | ||
285 | let ast_id = self.source_ast_id_map.ast_id(&module); | 289 | let ast_id = self.source_ast_id_map.ast_id(&module); |
286 | if module.has_semi() { | 290 | if module.semi_token().is_some() { |
287 | let item = | 291 | let item = |
288 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); | 292 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); |
289 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 293 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 4900000fe..0f806d6fb 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs | |||
@@ -28,7 +28,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
28 | loop { | 28 | loop { |
29 | let segment = path.segment()?; | 29 | let segment = path.segment()?; |
30 | 30 | ||
31 | if segment.has_colon_colon() { | 31 | if segment.coloncolon_token().is_some() { |
32 | kind = PathKind::Abs; | 32 | kind = PathKind::Abs; |
33 | } | 33 | } |
34 | 34 | ||
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index 278d5196e..5b6854b0f 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs | |||
@@ -34,7 +34,7 @@ pub(crate) fn lower_use_tree( | |||
34 | let alias = tree.alias().map(|a| { | 34 | let alias = tree.alias().map(|a| { |
35 | a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) | 35 | a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) |
36 | }); | 36 | }); |
37 | let is_glob = tree.has_star(); | 37 | let is_glob = tree.star_token().is_some(); |
38 | if let Some(ast_path) = tree.path() { | 38 | if let Some(ast_path) = tree.path() { |
39 | // Handle self in a path. | 39 | // Handle self in a path. |
40 | // E.g. `use something::{self, <...>}` | 40 | // E.g. `use something::{self, <...>}` |
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 01cc392db..7a8338937 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -77,7 +77,7 @@ impl TypeRef { | |||
77 | } | 77 | } |
78 | ast::TypeRef::PointerType(inner) => { | 78 | ast::TypeRef::PointerType(inner) => { |
79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
80 | let mutability = Mutability::from_mutable(inner.is_mut()); | 80 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); |
81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
82 | } | 82 | } |
83 | ast::TypeRef::ArrayType(inner) => { | 83 | ast::TypeRef::ArrayType(inner) => { |
@@ -88,7 +88,7 @@ impl TypeRef { | |||
88 | } | 88 | } |
89 | ast::TypeRef::ReferenceType(inner) => { | 89 | ast::TypeRef::ReferenceType(inner) => { |
90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
91 | let mutability = Mutability::from_mutable(inner.is_mut()); | 91 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); |
92 | TypeRef::Reference(Box::new(inner_ty), mutability) | 92 | TypeRef::Reference(Box::new(inner_ty), mutability) |
93 | } | 93 | } |
94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, | 94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, |
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs index 62513873e..1482d3be0 100644 --- a/crates/ra_hir_def/src/visibility.rs +++ b/crates/ra_hir_def/src/visibility.rs | |||
@@ -84,6 +84,10 @@ impl RawVisibility { | |||
84 | let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; | 84 | let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; |
85 | RawVisibility::Module(path) | 85 | RawVisibility::Module(path) |
86 | } | 86 | } |
87 | ast::VisibilityKind::PubSelf => { | ||
88 | let path = ModPath { kind: PathKind::Plain, segments: Vec::new() }; | ||
89 | RawVisibility::Module(path) | ||
90 | } | ||
87 | ast::VisibilityKind::Pub => RawVisibility::Public, | 91 | ast::VisibilityKind::Pub => RawVisibility::Public, |
88 | } | 92 | } |
89 | } | 93 | } |