mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 13:13:17 +00:00
Merge #8082
8082: Proper handle inner recursive macro rules cases r=edwin0cheng a=edwin0cheng Fixes #7645 cc @jonas-schievink bors r+ Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
d3da042a62
@ -115,6 +115,10 @@ impl ItemTree {
|
||||
// still need to collect inner items.
|
||||
ctx.lower_inner_items(stmt.syntax())
|
||||
},
|
||||
ast::Item(item) => {
|
||||
// Macros can expand to stmt and other item, and we add it as top level item
|
||||
ctx.lower_single_item(item)
|
||||
},
|
||||
_ => {
|
||||
panic!("cannot create item tree from {:?} {}", syntax, syntax);
|
||||
},
|
||||
|
@ -87,6 +87,14 @@ impl Ctx {
|
||||
self.tree
|
||||
}
|
||||
|
||||
pub(super) fn lower_single_item(mut self, item: ast::Item) -> ItemTree {
|
||||
self.tree.top_level = self
|
||||
.lower_mod_item(&item, false)
|
||||
.map(|item| item.0)
|
||||
.unwrap_or_else(|| Default::default());
|
||||
self.tree
|
||||
}
|
||||
|
||||
pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree {
|
||||
self.collect_inner_items(within);
|
||||
self.tree
|
||||
|
@ -231,6 +231,28 @@ fn expr_macro_expanded_in_stmts() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_inner_item_macro_rules() {
|
||||
check_infer(
|
||||
r#"
|
||||
macro_rules! mac {
|
||||
() => { mac!($)};
|
||||
($x:tt) => { macro_rules! blub { () => { 1 }; } };
|
||||
}
|
||||
fn foo() {
|
||||
mac!();
|
||||
let a = blub!();
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..1 '1': i32
|
||||
!0..7 'mac!($)': {unknown}
|
||||
107..143 '{ ...!(); }': ()
|
||||
129..130 'a': i32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_type_value_macro_having_same_name() {
|
||||
check_infer(
|
||||
|
Loading…
Reference in New Issue
Block a user