mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Merge #7136
7136: Fixed nested eager macro bug r=edwin0cheng a=edwin0cheng fixes #7126 bors r+ Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
354c1daedc
2 changed files with 52 additions and 0 deletions
|
@ -218,6 +218,12 @@ fn eager_macro_recur(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// check if the whole original sytnax is replaced
|
||||||
|
// Note that SyntaxRewriter cannot replace the root node itself
|
||||||
|
if child.syntax() == &original {
|
||||||
|
return Ok(insert);
|
||||||
|
}
|
||||||
|
|
||||||
rewriter.replace(child.syntax(), &insert);
|
rewriter.replace(child.syntax(), &insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -570,6 +570,52 @@ fn bar() -> u32 {0}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn infer_builtin_macros_include_str() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! include_str {() => {}}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = include_str!("foo.rs");
|
||||||
|
a;
|
||||||
|
} //^ &str
|
||||||
|
|
||||||
|
//- /foo.rs
|
||||||
|
hello
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn infer_builtin_macros_include_str_with_lazy_nested() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! concat {() => {}}
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! include_str {() => {}}
|
||||||
|
|
||||||
|
macro_rules! m {
|
||||||
|
($x:expr) => {
|
||||||
|
concat!("foo", $x)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = include_str!(m!(".rs"));
|
||||||
|
a;
|
||||||
|
} //^ &str
|
||||||
|
|
||||||
|
//- /foo.rs
|
||||||
|
hello
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn include_accidentally_quadratic() {
|
fn include_accidentally_quadratic() {
|
||||||
|
|
Loading…
Reference in a new issue