Skip to content

disallowed_names triggers within external macro generated code #14958

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
Nemo157 opened this issue Jun 2, 2025 · 2 comments · Fixed by #14976
Closed

disallowed_names triggers within external macro generated code #14958

Nemo157 opened this issue Jun 2, 2025 · 2 comments · Fixed by #14976
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

@Nemo157
Copy link
Member

Nemo157 commented Jun 2, 2025

Summary

disallowed_names triggers within external macro generated code. I noticed this when trying to remove err from a crate as it is used within syn::parse_macro_input!.

Lint Name

disallowed_names

Reproducer

I tried this code:

#![deny(clippy::disallowed_names)]

#[proc_macro]
pub fn foo(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let output = input.clone();
    let _ = syn::parse_macro_input!(input as syn::DeriveInput);
    output
}

with the config:

disallowed-names = ["err"]

I saw this happen:

error: use of a disallowed/placeholder name `err`
 --> src/lib.rs:6:13
  |
6 |     let _ = syn::parse_macro_input!(input as syn::DeriveInput);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![deny(clippy::disallowed_names)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this error originates in the macro `syn::parse_macro_input` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen:

No error since the identifier is within an external macro.

Version

rustc 1.88.0-nightly (2e6882ac5 2025-05-05)
binary: rustc
commit-hash: 2e6882ac5be27a73293d6f7ae56397fdf32848de
commit-date: 2025-05-05
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.4

Additional Labels

No response

@Nemo157 Nemo157 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 Jun 2, 2025
@donkomura
Copy link
Contributor

@rustbot claim

@Nemo157
Copy link
Member Author

Nemo157 commented Jun 3, 2025

Just happened across a simpler repro:

#[derive(Debug)] pub struct Foo;

with config

disallowed-names = ["f"]

gives

warning: use of a disallowed/placeholder name `f`
 --> src/lib.rs:1:10
  |
1 | #[derive(Debug)] pub struct Foo;
  |          ^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
  = note: `#[warn(clippy::disallowed_names)]` on by default

donkomura added a commit to donkomura/rust-clippy that referenced this issue Jun 4, 2025
Fixes rust-lang#14958

`disallowed_names` was used to lint code generated by macros.
This behavior can confuse programmers who did not write the macro
themselves. This change suppresses lints for code originating from
macros, including external ones.

changelog: [`disallowed_names`] do not lint macro generated codes
github-merge-queue bot pushed a commit that referenced this issue Jun 5, 2025
Fixes #14958

`disallowed_names` was used to lint code generated by macros. This
behavior can confuse programmers who did not write the macro themselves.
This change suppresses lints for code originating from macros, including
external ones.

changelog: [`disallowed_names`] do not lint macro generated codes
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.

2 participants