Skip to content
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

nonstandard_macro_braces false positive #7434

Closed
DmitrySamoylov opened this issue Jul 5, 2021 · 10 comments
Closed

nonstandard_macro_braces false positive #7434

DmitrySamoylov opened this issue Jul 5, 2021 · 10 comments
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

@DmitrySamoylov
Copy link

DmitrySamoylov commented Jul 5, 2021

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
    
@DmitrySamoylov DmitrySamoylov 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 Jul 5, 2021
@Lymia
Copy link

Lymia commented Jul 5, 2021

This also seems to happen with my crate enumset. I have a very similar use of the write! macro that has caused a very similar warning: https://github.com/Lymia/enumset/blob/master/enumset_derive/src/lib.rs#L318

Issue I got: Lymia/enumset#25

@williballenthin
Copy link

williballenthin commented Jul 6, 2021

And another data point:

warning: use of irregular braces for `vec!` macro
   --> pylancelot/src/lib.rs:283:1
    |
283 | #[pymethods]
    | ^^^^^^^^^^^^
    |
help: consider writing `#[pymethods]`
   --> pylancelot/src/lib.rs:283:1
    |
283 | #[pymethods]
    | ^^^^^^^^^^^^
    = 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 `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)

with the source:

#[pymethods]
impl Instruction {
    /// the length in bytes of the instruction.
    #[getter]
    pub fn length(&self) -> u8 {
        self.inner.length as u8
    }

@williballenthin
Copy link

I wonder if this was introduced with #7431. @DevinR528 does this look familiar?

@DevinR528
Copy link
Contributor

I'm making the assumption that that commit (#7431) is not in a released version of clippy? There was this issue #7422 and then the PR to close it so hopefully, the problem is that the fix just hasn't gotten into a release.

It also shouldn't be warning without the lint being explicitly turned on because it was moved to nursery which also makes me think it's not there yet although cargo +nightly clippy -V: clippy 0.1.55 (b3d11f9 2021-07-04) worries me since that's the date the PR was merged 🤷 someone more familiar with the release process could answer these questions better @llogiq (I hope I didn't further screw this up).

@giraffate
Copy link
Contributor

Although I don't know the details of that lint, we perform the sync between Clippy and rust-lang/rust every other week. So that fixes might not be applied in latest nightly yet.

@asomers
Copy link

asomers commented Jul 10, 2021

This warning is firing for Mockall, too. It looks like every project that uses Mockall will trigger the warning, and Clippy's suggested replacement code doesn't even compile.

@EliasHolzmann
Copy link
Contributor

Also seems to happen for Rocket attributes like get.

@shepmaster
Copy link
Member

This likely happens for any procedural macro that uses one of the macros checked by this lint. This jives with what is described in #7431

For example, in SNAFU, the procedural macro does:

let match_arm = quote! {
    #pattern_ident { #field_names } => {
        write!(#FORMATTER_ARG, #format)
    }
};

This generates code like

Error :: Leaf { ref user_id } =>
           { write! (__snafu_display_formatter, stringify! (Leaf)) }

Note the spaces between write! and (.

@asomers
Copy link

asomers commented Jul 17, 2021

It seems this issue was fixed, probably by #7431 . Can it be closed?

@giraffate
Copy link
Contributor

Yes, so I'm closing this.

Thanks for the reports!

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

No branches or pull requests

8 participants