Skip to content

unused_attributes false positive (top-level unused_crate_dependencies with feature(lint_reasons)) #111682

Closed
@Ltrlg

Description

@Ltrlg

I tried this code:

#![deny(unused_crate_dependencies)]
#![feature(lint_reasons)]

fn main() {}

unused_crate_dependencies is at top level, as expected. But I get the following warning:

warning: deny(unused_crate_dependencies) is ignored unless specified at crate level
 --> src/main.rs:1:9
  |
1 | #![deny(unused_crate_dependencies)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

Removing the #[feature(lint_reason)] removes the warning.

Interestingly, adding a #[deny(…)] removes the warning too:

#![deny(unused_crate_dependencies)]
#![deny(non_snake_case)]
#![feature(lint_reasons)]

fn main() {}

gives no warning.

But only at certain positions:

#![deny(non_snake_case)]
#![deny(unused_crate_dependencies)]
#![feature(lint_reasons)]

fn main() {}

gives the warning.

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (ce5919fce 2023-05-15)
binary: rustc
commit-hash: ce5919fcef67103098219e1868f741e56fc90963
commit-date: 2023-05-15
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

(But IIRC I had the warning already with 1.71.0-nightly (473f916d8 2023-05-03))

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions