diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-15 14:45:09 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-15 14:45:09 +0000 |
commit | bd4c352831662762ee7a66da77ec9adf623b0a0a (patch) | |
tree | 725dfad20b95344ad363b35860cf7e57067bb5e5 /crates/hir_expand/src/builtin_macro.rs | |
parent | 39aae835fd70d06092c1be1add6eef3984439529 (diff) | |
parent | 479babf8740a4d3cf6fc03a5f4a2fca00d387501 (diff) |
Merge #6893
6893: Move to upstream `macro_rules!` model r=matklad a=jonas-schievink
This changes `macro_rules!` from being treated as a macro invocation to being a first-class item. It also disallows using an additional ident argument for regular macros, so `m! ident(...);` now fails to parse.
This matches upstream Rust, and makes the code somewhat simpler by removing repeated "is this a `macro_rules!` call" checks. It will also simplify allowing visibilities on macros, which is currently being proposed in https://github.com/rust-lang/rust/pull/78166.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/builtin_macro.rs')
-rw-r--r-- | crates/hir_expand/src/builtin_macro.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index b1b432ded..bd9223825 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs | |||
@@ -63,7 +63,7 @@ macro_rules! register_builtin { | |||
63 | pub fn find_builtin_macro( | 63 | pub fn find_builtin_macro( |
64 | ident: &name::Name, | 64 | ident: &name::Name, |
65 | krate: CrateId, | 65 | krate: CrateId, |
66 | ast_id: AstId<ast::MacroCall>, | 66 | ast_id: AstId<ast::MacroRules>, |
67 | ) -> Option<MacroDefId> { | 67 | ) -> Option<MacroDefId> { |
68 | let kind = find_by_name(ident)?; | 68 | let kind = find_by_name(ident)?; |
69 | 69 | ||
@@ -515,12 +515,16 @@ mod tests { | |||
515 | fn expand_builtin_macro(ra_fixture: &str) -> String { | 515 | fn expand_builtin_macro(ra_fixture: &str) -> String { |
516 | let (db, file_id) = TestDB::with_single_file(&ra_fixture); | 516 | let (db, file_id) = TestDB::with_single_file(&ra_fixture); |
517 | let parsed = db.parse(file_id); | 517 | let parsed = db.parse(file_id); |
518 | let macro_rules: Vec<_> = | ||
519 | parsed.syntax_node().descendants().filter_map(ast::MacroRules::cast).collect(); | ||
518 | let macro_calls: Vec<_> = | 520 | let macro_calls: Vec<_> = |
519 | parsed.syntax_node().descendants().filter_map(ast::MacroCall::cast).collect(); | 521 | parsed.syntax_node().descendants().filter_map(ast::MacroCall::cast).collect(); |
520 | 522 | ||
521 | let ast_id_map = db.ast_id_map(file_id.into()); | 523 | let ast_id_map = db.ast_id_map(file_id.into()); |
522 | 524 | ||
523 | let expander = find_by_name(¯o_calls[0].name().unwrap().as_name()).unwrap(); | 525 | assert_eq!(macro_rules.len(), 1, "test must contain exactly 1 `macro_rules!`"); |
526 | assert_eq!(macro_calls.len(), 1, "test must contain exactly 1 macro call"); | ||
527 | let expander = find_by_name(¯o_rules[0].name().unwrap().as_name()).unwrap(); | ||
524 | 528 | ||
525 | let krate = CrateId(0); | 529 | let krate = CrateId(0); |
526 | let file_id = match expander { | 530 | let file_id = match expander { |
@@ -528,7 +532,7 @@ mod tests { | |||
528 | // the first one should be a macro_rules | 532 | // the first one should be a macro_rules |
529 | let def = MacroDefId { | 533 | let def = MacroDefId { |
530 | krate: Some(CrateId(0)), | 534 | krate: Some(CrateId(0)), |
531 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_calls[0]))), | 535 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_rules[0]))), |
532 | kind: MacroDefKind::BuiltIn(expander), | 536 | kind: MacroDefKind::BuiltIn(expander), |
533 | local_inner: false, | 537 | local_inner: false, |
534 | }; | 538 | }; |
@@ -538,7 +542,7 @@ mod tests { | |||
538 | krate, | 542 | krate, |
539 | kind: MacroCallKind::FnLike(AstId::new( | 543 | kind: MacroCallKind::FnLike(AstId::new( |
540 | file_id.into(), | 544 | file_id.into(), |
541 | ast_id_map.ast_id(¯o_calls[1]), | 545 | ast_id_map.ast_id(¯o_calls[0]), |
542 | )), | 546 | )), |
543 | }; | 547 | }; |
544 | 548 | ||
@@ -549,12 +553,12 @@ mod tests { | |||
549 | // the first one should be a macro_rules | 553 | // the first one should be a macro_rules |
550 | let def = MacroDefId { | 554 | let def = MacroDefId { |
551 | krate: Some(krate), | 555 | krate: Some(krate), |
552 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_calls[0]))), | 556 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_rules[0]))), |
553 | kind: MacroDefKind::BuiltInEager(expander), | 557 | kind: MacroDefKind::BuiltInEager(expander), |
554 | local_inner: false, | 558 | local_inner: false, |
555 | }; | 559 | }; |
556 | 560 | ||
557 | let args = macro_calls[1].token_tree().unwrap(); | 561 | let args = macro_calls[0].token_tree().unwrap(); |
558 | let parsed_args = mbe::ast_to_token_tree(&args).unwrap().0; | 562 | let parsed_args = mbe::ast_to_token_tree(&args).unwrap().0; |
559 | 563 | ||
560 | let arg_id = db.intern_eager_expansion({ | 564 | let arg_id = db.intern_eager_expansion({ |