mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
Improve fail case in expand_macro
This commit is contained in:
parent
5b19202e00
commit
9c521f00ff
1 changed files with 31 additions and 9 deletions
|
@ -47,8 +47,7 @@ fn expand_macro_recur(
|
|||
|
||||
for child in children.into_iter() {
|
||||
let node = hir::Source::new(macro_file_id, &child);
|
||||
let new_node = expand_macro_recur(db, source, node)?;
|
||||
|
||||
if let Some(new_node) = expand_macro_recur(db, source, node) {
|
||||
// Replace the whole node if it is root
|
||||
// `replace_descendants` will not replace the parent node
|
||||
// but `SyntaxNode::descendants include itself
|
||||
|
@ -58,6 +57,7 @@ fn expand_macro_recur(
|
|||
replaces.insert(child.syntax().clone().into(), new_node.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(replace_descendants(&expanded, &replaces))
|
||||
}
|
||||
|
@ -247,4 +247,26 @@ fn some_thing() -> u32 {
|
|||
assert_eq!(res.name, "match_ast");
|
||||
assert_snapshot!(res.expansion, @r###"{}"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_expand_inner_macro_fail_to_expand() {
|
||||
let res = check_expand_macro(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
macro_rules! bar {
|
||||
(BAD) => {};
|
||||
}
|
||||
macro_rules! foo {
|
||||
() => {bar!()};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let res = fo<|>o!();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
assert_eq!(res.name, "foo");
|
||||
assert_snapshot!(res.expansion, @r###"bar!()"###);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue