diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-18 14:38:04 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-18 14:38:04 +0000 |
commit | 3ab9b39dd47d99ffd97f485c27f38b8944e12a3e (patch) | |
tree | 308ffffd0b61517f13aedad9621430f4c41014e3 /crates/hir_expand/src/lib.rs | |
parent | 816bc7389516dda1eb4821f2ac4d5993cd5611dd (diff) | |
parent | b84efbaacfc980ba167edc145aa7ca5d738448ff (diff) |
Merge #8087
8087: Make MacroDefId's `AstId` mandatory when possible r=jonas-schievink a=jonas-schievink
This makes it clearer (in the type definition) which macros have or don't have an `AstId`
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r-- | crates/hir_expand/src/lib.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 7532d00b8..83e11019f 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs | |||
@@ -143,7 +143,7 @@ impl HirFileId { | |||
143 | 143 | ||
144 | let arg_tt = loc.kind.arg(db)?; | 144 | let arg_tt = loc.kind.arg(db)?; |
145 | 145 | ||
146 | let def = loc.def.ast_id.and_then(|id| { | 146 | let def = loc.def.ast_id().and_then(|id| { |
147 | let def_tt = match id.to_node(db) { | 147 | let def_tt = match id.to_node(db) { |
148 | ast::Macro::MacroRules(mac) => mac.token_tree()?, | 148 | ast::Macro::MacroRules(mac) => mac.token_tree()?, |
149 | ast::Macro::MacroDef(_) => return None, | 149 | ast::Macro::MacroDef(_) => return None, |
@@ -180,7 +180,7 @@ impl HirFileId { | |||
180 | }; | 180 | }; |
181 | let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id); | 181 | let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id); |
182 | let item = match loc.def.kind { | 182 | let item = match loc.def.kind { |
183 | MacroDefKind::BuiltInDerive(_) => loc.kind.node(db), | 183 | MacroDefKind::BuiltInDerive(..) => loc.kind.node(db), |
184 | _ => return None, | 184 | _ => return None, |
185 | }; | 185 | }; |
186 | Some(item.with_value(ast::Item::cast(item.value.clone())?)) | 186 | Some(item.with_value(ast::Item::cast(item.value.clone())?)) |
@@ -224,7 +224,6 @@ impl From<EagerMacroId> for MacroCallId { | |||
224 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 224 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
225 | pub struct MacroDefId { | 225 | pub struct MacroDefId { |
226 | pub krate: CrateId, | 226 | pub krate: CrateId, |
227 | pub ast_id: Option<AstId<ast::Macro>>, | ||
228 | pub kind: MacroDefKind, | 227 | pub kind: MacroDefKind, |
229 | 228 | ||
230 | pub local_inner: bool, | 229 | pub local_inner: bool, |
@@ -239,15 +238,26 @@ impl MacroDefId { | |||
239 | ) -> LazyMacroId { | 238 | ) -> LazyMacroId { |
240 | db.intern_macro(MacroCallLoc { def: self, krate, kind }) | 239 | db.intern_macro(MacroCallLoc { def: self, krate, kind }) |
241 | } | 240 | } |
241 | |||
242 | pub fn ast_id(&self) -> Option<AstId<ast::Macro>> { | ||
243 | let id = match &self.kind { | ||
244 | MacroDefKind::Declarative(id) => id, | ||
245 | MacroDefKind::BuiltIn(_, id) => id, | ||
246 | MacroDefKind::BuiltInDerive(_, id) => id, | ||
247 | MacroDefKind::BuiltInEager(_, id) => id, | ||
248 | MacroDefKind::ProcMacro(_) => return None, | ||
249 | }; | ||
250 | Some(*id) | ||
251 | } | ||
242 | } | 252 | } |
243 | 253 | ||
244 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 254 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
245 | pub enum MacroDefKind { | 255 | pub enum MacroDefKind { |
246 | Declarative, | 256 | Declarative(AstId<ast::Macro>), |
247 | BuiltIn(BuiltinFnLikeExpander), | 257 | BuiltIn(BuiltinFnLikeExpander, AstId<ast::Macro>), |
248 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander | 258 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander |
249 | BuiltInDerive(BuiltinDeriveExpander), | 259 | BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>), |
250 | BuiltInEager(EagerExpander), | 260 | BuiltInEager(EagerExpander, AstId<ast::Macro>), |
251 | ProcMacro(ProcMacroExpander), | 261 | ProcMacro(ProcMacroExpander), |
252 | } | 262 | } |
253 | 263 | ||