Skip to content

nonstandard_macro_braces false positive #7434

@DmitrySamoylov

Description

@DmitrySamoylov

Lint name: nonstandard_macro_braces

I tried this code:

[package]
name = "nonstandard_macro_braces_issue"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = "1.0.41"
fn-error-context = "0.1.2"
use fn_error_context::context;

fn main() {
    let _ = my_fn();
}

#[context("Some anyhow context")]
pub fn my_fn() -> anyhow::Result<()> {
    Ok(())
}

I expected to see no warnings

Instead, this happened (cargo +nightly clippy):

warning: use of irregular braces for `format!` macro
 --> src/main.rs:7:1
  |
7 | #[context("Some anyhow context")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::nonstandard_macro_braces)]` on by default
help: consider writing `#(context("Some anyhow context"))`
 --> src/main.rs:7:1
  |
7 | #[context("Some anyhow context")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces
  = note: this warning originates in the attribute macro `context` (in Nightly builds, run with -Z macro-backtrace for more info)

context macro sources

Meta

  • cargo clippy -V: clippy 0.1.53 (53cb7b0 2021-06-17)
  • cargo +nightly clippy -V: clippy 0.1.55 (b3d11f9 2021-07-04)
  • rustc -Vv:
    rustc 1.53.0 (53cb7b09b 2021-06-17)
    binary: rustc
    commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
    commit-date: 2021-06-17
    host: x86_64-unknown-linux-gnu
    release: 1.53.0
    LLVM version: 12.0.1
    

Metadata

Metadata

Assignees

No one assigned

    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