Skip to content

Commit f5c3ed4

Browse files
committed
Only trigger for one level of macros
1 parent 5bc5bfc commit f5c3ed4

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

clippy_lints/src/nonstandard_macro_braces.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl EarlyLintPass for MacroBraces {
9494

9595
fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a MacroBraces) -> Option<MacroInfo<'a>> {
9696
if_chain! {
97-
if in_macro(span);
97+
// Make sure we are only one level deep otherwise there are to many FP's
98+
if in_macro(span) && !in_macro(span.ctxt().outer_expn_data().call_site);
9899
if let Some((name, braces)) = find_matching_macro(span, &mac_braces.macro_braces);
99100
if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site);
100101
// we must check only invocation sites

tests/ui-toml/nonstandard_macro_braces/clippy.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ standard-macro-braces = [
33
{ name = "quote::quote", brace = "{" },
44
{ name = "eprint", brace = "[" },
55
{ name = "type_pos", brace = "[" },
6-
{ name = "printlnfoo", brace = "[" },
76
]

tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ macro_rules! type_pos {
3434

3535
macro_rules! printlnfoo {
3636
($thing:expr) => {
37-
println!("hey {}", $thing)
37+
println!("{}", $thing)
3838
};
3939
}
4040

@@ -44,7 +44,7 @@ fn main() {
4444
let _ = format!["ugh {} stop being such a good compiler", "hello"];
4545
let _ = quote!(let x = 1;);
4646
let _ = quote::quote!(match match match);
47-
let _ = test!();
47+
let _ = test!(); // don't trigger for macro calls inside macros
4848
let _ = vec![1,2,3];
4949

5050
let _ = quote::quote! {true || false};
@@ -56,7 +56,5 @@ fn main() {
5656

5757
eprint!("test if user config overrides defaults");
5858

59-
println!("test if println triggers for printlnfoo");
60-
61-
printlnfoo!("you");
59+
printlnfoo!["test if printlnfoo is triggered by println"];
6260
}

tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,6 @@ help: consider writing `quote::quote! {match match match}`
4747
LL | let _ = quote::quote!(match match match);
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949

50-
error: use of irregular braces for `vec!` macro
51-
--> $DIR/conf_nonstandard_macro_braces.rs:18:9
52-
|
53-
LL | vec!{0, 0, 0}
54-
| ^^^^^^^^^^^^^
55-
...
56-
LL | let _ = test!();
57-
| ------- in this macro invocation
58-
|
59-
help: consider writing `vec![0, 0, 0]`
60-
--> $DIR/conf_nonstandard_macro_braces.rs:18:9
61-
|
62-
LL | vec!{0, 0, 0}
63-
| ^^^^^^^^^^^^^
64-
...
65-
LL | let _ = test!();
66-
| ------- in this macro invocation
67-
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
68-
6950
error: use of irregular braces for `type_pos!` macro
7051
--> $DIR/conf_nonstandard_macro_braces.rs:55:12
7152
|
@@ -90,17 +71,5 @@ help: consider writing `eprint!["test if user config overrides defaults"];`
9071
LL | eprint!("test if user config overrides defaults");
9172
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9273

93-
error: use of irregular braces for `printlnfoo!` macro
94-
--> $DIR/conf_nonstandard_macro_braces.rs:61:5
95-
|
96-
LL | printlnfoo!("you");
97-
| ^^^^^^^^^^^^^^^^^^^
98-
|
99-
help: consider writing `printlnfoo!["you"];`
100-
--> $DIR/conf_nonstandard_macro_braces.rs:61:5
101-
|
102-
LL | printlnfoo!("you");
103-
| ^^^^^^^^^^^^^^^^^^^
104-
105-
error: aborting due to 8 previous errors
74+
error: aborting due to 6 previous errors
10675

0 commit comments

Comments
 (0)