rust-clippy
rust-clippy copied to clipboard
allow_attributes lint triggers inside derive macro
Summary
I tried using the new clippy lint allow_attributes on one of my projects and found many warnings for structs deriving bytemuck::Pod.
I am using bytemuck and checking the output of cargo expand there is an #[allow(clippy::missing_const_for_fn)] in the generated code.
Of course using cargo clippy --fix doesn't work in this case too because it tries to replace the #[repr(C)] with expect.
Reproducer
I tried this code:
#![expect(unused)]
#![warn(clippy::allow_attributes)]
fn main() {}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct Foo {
a: u32,
}
I expected to see this happen: No clippy lints
Instead, this happened:
warning: #[allow] attribute found
--> src/main.rs:4:1
|
4 | #[repr(C)]
| ^ help: replace it with: `expect`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
note: the lint level is defined here
--> src/main.rs:2:9
|
2 | #![warn(clippy::allow_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
warning: `clippy_experiment` (bin "clippy_experiment") generated 1 warning (run `cargo clippy --fix --bin "clippy_experiment"` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.52s
Version
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
Additional Labels
No response