mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Fix nested macro in block defining items
This commit is contained in:
parent
e8b9f43084
commit
28e4b10f46
2 changed files with 41 additions and 0 deletions
|
@ -312,3 +312,35 @@ mod m {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nested_macro_item_decl() {
|
||||||
|
cov_mark::check!(macro_call_in_macro_stmts_is_added_to_item_tree);
|
||||||
|
check_at(
|
||||||
|
r#"
|
||||||
|
macro_rules! inner_declare {
|
||||||
|
($ident:ident) => {
|
||||||
|
static $ident: u32 = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! declare {
|
||||||
|
($ident:ident) => {
|
||||||
|
inner_declare!($ident);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
declare!(bar);
|
||||||
|
bar;
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
block scope
|
||||||
|
bar: v
|
||||||
|
|
||||||
|
crate
|
||||||
|
foo: v
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,15 @@ impl<'a> Ctx<'a> {
|
||||||
.statements()
|
.statements()
|
||||||
.filter_map(|stmt| match stmt {
|
.filter_map(|stmt| match stmt {
|
||||||
ast::Stmt::Item(item) => Some(item),
|
ast::Stmt::Item(item) => Some(item),
|
||||||
|
// Macro calls can be both items and expressions. The syntax library always treats
|
||||||
|
// them as expressions here, so we undo that.
|
||||||
|
ast::Stmt::ExprStmt(es) => match es.expr()? {
|
||||||
|
ast::Expr::MacroCall(call) => {
|
||||||
|
cov_mark::hit!(macro_call_in_macro_stmts_is_added_to_item_tree);
|
||||||
|
Some(call.into())
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.flat_map(|item| self.lower_mod_item(&item, false))
|
.flat_map(|item| self.lower_mod_item(&item, false))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue