diff options
author | Jonas Schievink <[email protected]> | 2021-04-08 19:43:07 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-08 19:43:07 +0100 |
commit | 86b7861612ba074120dfb6bd32c80c569688748d (patch) | |
tree | 3403086d9e04417e92b0c3ad2af09151e698a3c5 /crates/hir_expand | |
parent | 5f279d57f0cba600eae8c550654a00b4268812ac (diff) |
Use named fields in `MacroCallKind`
Diffstat (limited to 'crates/hir_expand')
-rw-r--r-- | crates/hir_expand/src/builtin_derive.rs | 4 | ||||
-rw-r--r-- | crates/hir_expand/src/builtin_macro.rs | 7 | ||||
-rw-r--r-- | crates/hir_expand/src/eager.rs | 5 | ||||
-rw-r--r-- | crates/hir_expand/src/lib.rs | 18 |
4 files changed, 18 insertions, 16 deletions
diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index 6ece4b289..392079ed4 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs | |||
@@ -308,7 +308,7 @@ $0 | |||
308 | 308 | ||
309 | let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); | 309 | let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); |
310 | 310 | ||
311 | let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); | 311 | let ast_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); |
312 | 312 | ||
313 | let loc = MacroCallLoc { | 313 | let loc = MacroCallLoc { |
314 | def: MacroDefId { | 314 | def: MacroDefId { |
@@ -317,7 +317,7 @@ $0 | |||
317 | local_inner: false, | 317 | local_inner: false, |
318 | }, | 318 | }, |
319 | krate: CrateId(0), | 319 | krate: CrateId(0), |
320 | kind: MacroCallKind::Derive(attr_id, name.to_string()), | 320 | kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() }, |
321 | }; | 321 | }; |
322 | 322 | ||
323 | let id: MacroCallId = db.intern_macro(loc).into(); | 323 | let id: MacroCallId = db.intern_macro(loc).into(); |
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index a7d0f5b1f..80365fc16 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs | |||
@@ -566,10 +566,9 @@ mod tests { | |||
566 | let loc = MacroCallLoc { | 566 | let loc = MacroCallLoc { |
567 | def, | 567 | def, |
568 | krate, | 568 | krate, |
569 | kind: MacroCallKind::FnLike(AstId::new( | 569 | kind: MacroCallKind::FnLike { |
570 | file_id.into(), | 570 | ast_id: AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)), |
571 | ast_id_map.ast_id(¯o_call), | 571 | }, |
572 | )), | ||
573 | }; | 572 | }; |
574 | 573 | ||
575 | let id: MacroCallId = db.intern_macro(loc).into(); | 574 | let id: MacroCallId = db.intern_macro(loc).into(); |
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 9705526fa..ef126e4ad 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs | |||
@@ -174,8 +174,9 @@ fn lazy_expand( | |||
174 | ) -> ExpandResult<Option<InFile<SyntaxNode>>> { | 174 | ) -> ExpandResult<Option<InFile<SyntaxNode>>> { |
175 | let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value); | 175 | let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value); |
176 | 176 | ||
177 | let id: MacroCallId = | 177 | let id: MacroCallId = def |
178 | def.as_lazy_macro(db, krate, MacroCallKind::FnLike(macro_call.with_value(ast_id))).into(); | 178 | .as_lazy_macro(db, krate, MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id) }) |
179 | .into(); | ||
179 | 180 | ||
180 | let err = db.macro_expand_error(id); | 181 | let err = db.macro_expand_error(id); |
181 | let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); | 182 | let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); |
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 3e332ee47..a179102f0 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs | |||
@@ -290,22 +290,24 @@ pub struct MacroCallLoc { | |||
290 | 290 | ||
291 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 291 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
292 | pub enum MacroCallKind { | 292 | pub enum MacroCallKind { |
293 | FnLike(AstId<ast::MacroCall>), | 293 | FnLike { ast_id: AstId<ast::MacroCall> }, |
294 | Derive(AstId<ast::Item>, String), | 294 | Derive { ast_id: AstId<ast::Item>, derive_name: String }, |
295 | } | 295 | } |
296 | 296 | ||
297 | impl MacroCallKind { | 297 | impl MacroCallKind { |
298 | fn file_id(&self) -> HirFileId { | 298 | fn file_id(&self) -> HirFileId { |
299 | match self { | 299 | match self { |
300 | MacroCallKind::FnLike(ast_id) => ast_id.file_id, | 300 | MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id, |
301 | MacroCallKind::Derive(ast_id, _) => ast_id.file_id, | 301 | MacroCallKind::Derive { ast_id, .. } => ast_id.file_id, |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { | 305 | fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { |
306 | match self { | 306 | match self { |
307 | MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), | 307 | MacroCallKind::FnLike { ast_id, .. } => { |
308 | MacroCallKind::Derive(ast_id, _) => { | 308 | ast_id.with_value(ast_id.to_node(db).syntax().clone()) |
309 | } | ||
310 | MacroCallKind::Derive { ast_id, .. } => { | ||
309 | ast_id.with_value(ast_id.to_node(db).syntax().clone()) | 311 | ast_id.with_value(ast_id.to_node(db).syntax().clone()) |
310 | } | 312 | } |
311 | } | 313 | } |
@@ -313,10 +315,10 @@ impl MacroCallKind { | |||
313 | 315 | ||
314 | fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { | 316 | fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { |
315 | match self { | 317 | match self { |
316 | MacroCallKind::FnLike(ast_id) => { | 318 | MacroCallKind::FnLike { ast_id, .. } => { |
317 | Some(ast_id.to_node(db).token_tree()?.syntax().clone()) | 319 | Some(ast_id.to_node(db).token_tree()?.syntax().clone()) |
318 | } | 320 | } |
319 | MacroCallKind::Derive(ast_id, _) => Some(ast_id.to_node(db).syntax().clone()), | 321 | MacroCallKind::Derive { ast_id, .. } => Some(ast_id.to_node(db).syntax().clone()), |
320 | } | 322 | } |
321 | } | 323 | } |
322 | } | 324 | } |