Only trigger for one level of macros
This commit is contained in:
parent
5bc5bfce04
commit
f5c3ed4463
clippy_lints/src
tests/ui-toml/nonstandard_macro_braces
@ -94,7 +94,8 @@ impl EarlyLintPass for MacroBraces {
|
||||
|
||||
fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a MacroBraces) -> Option<MacroInfo<'a>> {
|
||||
if_chain! {
|
||||
if in_macro(span);
|
||||
// Make sure we are only one level deep otherwise there are to many FP's
|
||||
if in_macro(span) && !in_macro(span.ctxt().outer_expn_data().call_site);
|
||||
if let Some((name, braces)) = find_matching_macro(span, &mac_braces.macro_braces);
|
||||
if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site);
|
||||
// we must check only invocation sites
|
||||
|
@ -3,5 +3,4 @@ standard-macro-braces = [
|
||||
{ name = "quote::quote", brace = "{" },
|
||||
{ name = "eprint", brace = "[" },
|
||||
{ name = "type_pos", brace = "[" },
|
||||
{ name = "printlnfoo", brace = "[" },
|
||||
]
|
||||
|
@ -34,7 +34,7 @@ macro_rules! type_pos {
|
||||
|
||||
macro_rules! printlnfoo {
|
||||
($thing:expr) => {
|
||||
println!("hey {}", $thing)
|
||||
println!("{}", $thing)
|
||||
};
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ fn main() {
|
||||
let _ = format!["ugh {} stop being such a good compiler", "hello"];
|
||||
let _ = quote!(let x = 1;);
|
||||
let _ = quote::quote!(match match match);
|
||||
let _ = test!();
|
||||
let _ = test!(); // don't trigger for macro calls inside macros
|
||||
let _ = vec![1,2,3];
|
||||
|
||||
let _ = quote::quote! {true || false};
|
||||
@ -56,7 +56,5 @@ fn main() {
|
||||
|
||||
eprint!("test if user config overrides defaults");
|
||||
|
||||
println!("test if println triggers for printlnfoo");
|
||||
|
||||
printlnfoo!("you");
|
||||
printlnfoo!["test if printlnfoo is triggered by println"];
|
||||
}
|
||||
|
@ -47,25 +47,6 @@ help: consider writing `quote::quote! {match match match}`
|
||||
LL | let _ = quote::quote!(match match match);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of irregular braces for `vec!` macro
|
||||
--> $DIR/conf_nonstandard_macro_braces.rs:18:9
|
||||
|
|
||||
LL | vec!{0, 0, 0}
|
||||
| ^^^^^^^^^^^^^
|
||||
...
|
||||
LL | let _ = test!();
|
||||
| ------- in this macro invocation
|
||||
|
|
||||
help: consider writing `vec![0, 0, 0]`
|
||||
--> $DIR/conf_nonstandard_macro_braces.rs:18:9
|
||||
|
|
||||
LL | vec!{0, 0, 0}
|
||||
| ^^^^^^^^^^^^^
|
||||
...
|
||||
LL | let _ = test!();
|
||||
| ------- in this macro invocation
|
||||
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: use of irregular braces for `type_pos!` macro
|
||||
--> $DIR/conf_nonstandard_macro_braces.rs:55:12
|
||||
|
|
||||
@ -90,17 +71,5 @@ help: consider writing `eprint!["test if user config overrides defaults"];`
|
||||
LL | eprint!("test if user config overrides defaults");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of irregular braces for `printlnfoo!` macro
|
||||
--> $DIR/conf_nonstandard_macro_braces.rs:61:5
|
||||
|
|
||||
LL | printlnfoo!("you");
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider writing `printlnfoo!["you"];`
|
||||
--> $DIR/conf_nonstandard_macro_braces.rs:61:5
|
||||
|
|
||||
LL | printlnfoo!("you");
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user