Skip to content

nonstandard_macro_braces replacing braces in the macro argument #9498

Closed
@kraktus

Description

@kraktus

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions