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

allow(clippy::duplicated_attributes) does not take effect across out-of-line modules #12538

Open
dtolnay opened this issue Mar 23, 2024 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 23, 2024

Summary

For this particular lint, module-level #![allow(clippy::duplicated_attributes)] suppresses occurrences of the lint within that module, and within in-line modules in the same file, but not in modules from other files.

This behavior is unlike what happens with allow for all other clippy lints, in which it applies to the whole module hierarchy across files.

Reproducer

// src/lib.rs

#![allow(clippy::duplicated_attributes)]

pub mod here {
    #[allow(dead_code)]
    #[allow(dead_code)]
    pub fn foo() {}
}

pub mod there;
// src/there.rs

#[allow(dead_code)]
#[allow(dead_code)]
pub fn foo() {}
$ cargo clippy
warning: duplicated attribute
 --> src/there.rs:4:9
  |
4 | #[allow(dead_code)]
  |         ^^^^^^^^^
  |
note: first defined here
 --> src/there.rs:3:9
  |
3 | #[allow(dead_code)]
  |         ^^^^^^^^^
help: remove this attribute
 --> src/there.rs:4:9
  |
4 | #[allow(dead_code)]
  |         ^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
  = note: `#[warn(clippy::duplicated_attributes)]` on by default

The occurrence within mod here is suppressed by the allow but the one within mod there is not.

Version

rustc 1.79.0-nightly (85e449a32 2024-03-22)
binary: rustc
commit-hash: 85e449a3237e82c9ade8936a82bd4fc64cfe1057
commit-date: 2024-03-22
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

@dtolnay dtolnay added the C-bug Category: Clippy is not doing the correct thing label Mar 23, 2024
@dtolnay
Copy link
Member Author

dtolnay commented Mar 23, 2024

@GuillaumeGomez @blyxyas (the lint is new from #12378)

dtolnay added a commit to dtolnay/cxx that referenced this issue Mar 23, 2024
…y bug

There is already #![allow(clippy::duplicated_attributes)] at the crate
root, but clippy isn't applying it correctly inside this module.

rust-lang/rust-clippy#12538
@J-ZhengLi
Copy link
Member

J-ZhengLi commented Mar 23, 2024

It appears to be another victim of early pass, just like the one lint from #12436

@rustbot label -I-false-positive

edit: I wonder what else can be done except moving those to late pass tho 🤔

@rustbot rustbot added I-false-positive Issue: The lint was triggered on code it shouldn't have and removed I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 23, 2024
@y21
Copy link
Member

y21 commented Mar 23, 2024

we should also probably add a comment here saying that you should prefer adding the lint to Attributes (instead of EarlyAttributes) if at all possible since this is what's causing these issues

impl_lint_pass!(EarlyAttributes => [

taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
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
Projects
None yet
Development

No branches or pull requests

4 participants