Skip to content

nonstandard_macro_braces replacing braces in the macro argument #9498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kraktus opened this issue Sep 19, 2022 · 1 comment · Fixed by #9499
Closed

nonstandard_macro_braces replacing braces in the macro argument #9498

kraktus opened this issue Sep 19, 2022 · 1 comment · Fixed by #9499
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@kraktus
Copy link
Contributor

kraktus commented Sep 19, 2022

Summary

nonstandard_macro_braces also replace braces/brackets/parenthesis that are in the macro arguments. This issue is there from initial implementation #7299, which even included a test with format! displaying the issue.

Lint Name

nonstandard_macro_braces

Reproducer

I tried this code:

#![warn(clippy::nonstandard_macro_braces)]

fn main(){
    let bar = "bar";
    println!["foo {}", bar]
}

I saw this happen:

Checking playground v0.0.1 (/playground)
warning: use of irregular braces for `println!` macro
 --> src/main.rs:5:5
  |
5 |     println!["foo {}", bar]
  |     ^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::nonstandard_macro_braces)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider writing `println!("foo ()", bar)`

Notice the parenthesis after foo, which break string interpolation.

I expected to see this happen:

Checking playground v0.0.1 (/playground)
warning: use of irregular braces for `println!` macro
 --> src/main.rs:5:5
  |
5 |     println!["foo {}", bar]
  |     ^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::nonstandard_macro_braces)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider writing `println!("foo {}", bar)`

Macro argument should be unchanged

Version

clippy 0.1.65 2022-09-18 a37499a

Additional Labels

@rustbot label +I-suggestion-cause-error

@kraktus kraktus added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Sep 19, 2022
@kraktus
Copy link
Contributor Author

kraktus commented Sep 19, 2022

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant