diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/has_source.rs | 15 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 8 |
3 files changed, 27 insertions, 16 deletions
diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 262002671..d57fad9ed 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs | |||
@@ -6,7 +6,7 @@ use hir_def::{ | |||
6 | src::{HasChildSource, HasSource as _}, | 6 | src::{HasChildSource, HasSource as _}, |
7 | Lookup, VariantId, | 7 | Lookup, VariantId, |
8 | }; | 8 | }; |
9 | use hir_expand::InFile; | 9 | use hir_expand::{InFile, MacroDefKind}; |
10 | use syntax::ast; | 10 | use syntax::ast; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
@@ -111,10 +111,17 @@ impl HasSource for TypeAlias { | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | impl HasSource for MacroDef { | 113 | impl HasSource for MacroDef { |
114 | type Ast = ast::Macro; | 114 | type Ast = Either<ast::Macro, ast::Fn>; |
115 | fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> { | 115 | fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> { |
116 | let ast_id = self.id.ast_id?; | 116 | Some(match &self.id.kind { |
117 | Some(InFile { file_id: ast_id.file_id, value: ast_id.to_node(db.upcast()) }) | 117 | MacroDefKind::Declarative(id) |
118 | | MacroDefKind::BuiltIn(_, id) | ||
119 | | MacroDefKind::BuiltInDerive(_, id) | ||
120 | | MacroDefKind::BuiltInEager(_, id) => { | ||
121 | id.with_value(Either::Left(id.to_node(db.upcast()))) | ||
122 | } | ||
123 | MacroDefKind::ProcMacro(_, id) => id.map(|_| Either::Right(id.to_node(db.upcast()))), | ||
124 | }) | ||
118 | } | 125 | } |
119 | } | 126 | } |
120 | impl HasSource for Impl { | 127 | impl HasSource for Impl { |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index b41a36a78..67ec8e82a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -1144,17 +1144,21 @@ impl MacroDef { | |||
1144 | 1144 | ||
1145 | /// XXX: this parses the file | 1145 | /// XXX: this parses the file |
1146 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1146 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1147 | self.source(db)?.value.name().map(|it| it.as_name()) | 1147 | match self.source(db)?.value { |
1148 | Either::Left(it) => it.name().map(|it| it.as_name()), | ||
1149 | Either::Right(it) => it.name().map(|it| it.as_name()), | ||
1150 | } | ||
1148 | } | 1151 | } |
1149 | 1152 | ||
1150 | /// Indicate it is a proc-macro | 1153 | /// Indicate it is a proc-macro |
1151 | pub fn is_proc_macro(&self) -> bool { | 1154 | pub fn is_proc_macro(&self) -> bool { |
1152 | matches!(self.id.kind, MacroDefKind::ProcMacro(_)) | 1155 | matches!(self.id.kind, MacroDefKind::ProcMacro(..)) |
1153 | } | 1156 | } |
1154 | 1157 | ||
1155 | /// Indicate it is a derive macro | 1158 | /// Indicate it is a derive macro |
1156 | pub fn is_derive_macro(&self) -> bool { | 1159 | pub fn is_derive_macro(&self) -> bool { |
1157 | matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_)) | 1160 | // FIXME: wrong for `ProcMacro` |
1161 | matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..)) | ||
1158 | } | 1162 | } |
1159 | } | 1163 | } |
1160 | 1164 | ||
@@ -1458,7 +1462,7 @@ impl TypeParam { | |||
1458 | .into_iter() | 1462 | .into_iter() |
1459 | .filter_map(|pred| match &pred.value { | 1463 | .filter_map(|pred| match &pred.value { |
1460 | hir_ty::GenericPredicate::Implemented(trait_ref) => { | 1464 | hir_ty::GenericPredicate::Implemented(trait_ref) => { |
1461 | Some(Trait::from(trait_ref.trait_)) | 1465 | Some(Trait::from(trait_ref.hir_trait_id())) |
1462 | } | 1466 | } |
1463 | _ => None, | 1467 | _ => None, |
1464 | }) | 1468 | }) |
@@ -1753,8 +1757,8 @@ impl Type { | |||
1753 | 1757 | ||
1754 | pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool { | 1758 | pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool { |
1755 | let trait_ref = hir_ty::TraitRef { | 1759 | let trait_ref = hir_ty::TraitRef { |
1756 | trait_: trait_.id, | 1760 | trait_id: hir_ty::to_chalk_trait_id(trait_.id), |
1757 | substs: Substitution::build_for_def(db, trait_.id) | 1761 | substitution: Substitution::build_for_def(db, trait_.id) |
1758 | .push(self.ty.value.clone()) | 1762 | .push(self.ty.value.clone()) |
1759 | .fill(args.iter().map(|t| t.ty.value.clone())) | 1763 | .fill(args.iter().map(|t| t.ty.value.clone())) |
1760 | .build(), | 1764 | .build(), |
@@ -2019,7 +2023,7 @@ impl Type { | |||
2019 | it.into_iter() | 2023 | it.into_iter() |
2020 | .filter_map(|pred| match pred { | 2024 | .filter_map(|pred| match pred { |
2021 | hir_ty::GenericPredicate::Implemented(trait_ref) => { | 2025 | hir_ty::GenericPredicate::Implemented(trait_ref) => { |
2022 | Some(Trait::from(trait_ref.trait_)) | 2026 | Some(Trait::from(trait_ref.hir_trait_id())) |
2023 | } | 2027 | } |
2024 | _ => None, | 2028 | _ => None, |
2025 | }) | 2029 | }) |
@@ -2063,7 +2067,7 @@ impl Type { | |||
2063 | match pred { | 2067 | match pred { |
2064 | GenericPredicate::Implemented(trait_ref) => { | 2068 | GenericPredicate::Implemented(trait_ref) => { |
2065 | cb(type_.clone()); | 2069 | cb(type_.clone()); |
2066 | walk_substs(db, type_, &trait_ref.substs, cb); | 2070 | walk_substs(db, type_, &trait_ref.substitution, cb); |
2067 | } | 2071 | } |
2068 | _ => (), | 2072 | _ => (), |
2069 | } | 2073 | } |
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index c6ad5ecb5..762809fcd 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs | |||
@@ -195,12 +195,12 @@ impl SourceToDefCtx<'_, '_> { | |||
195 | &mut self, | 195 | &mut self, |
196 | src: InFile<ast::MacroRules>, | 196 | src: InFile<ast::MacroRules>, |
197 | ) -> Option<MacroDefId> { | 197 | ) -> Option<MacroDefId> { |
198 | let kind = MacroDefKind::Declarative; | 198 | let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); |
199 | let ast_id = AstId::new(src.file_id, file_ast_id.upcast()); | ||
200 | let kind = MacroDefKind::Declarative(ast_id); | ||
199 | let file_id = src.file_id.original_file(self.db.upcast()); | 201 | let file_id = src.file_id.original_file(self.db.upcast()); |
200 | let krate = self.file_to_def(file_id).get(0).copied()?.krate(); | 202 | let krate = self.file_to_def(file_id).get(0).copied()?.krate(); |
201 | let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); | 203 | Some(MacroDefId { krate, kind, local_inner: false }) |
202 | let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast())); | ||
203 | Some(MacroDefId { krate, ast_id, kind, local_inner: false }) | ||
204 | } | 204 | } |
205 | 205 | ||
206 | pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { | 206 | pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { |