Skip to content

expect(dead_code) on a crate or mod level does not play well with unfulfilled_lint_expectations #154324

@zacknewman

Description

@zacknewman

Not sure if this is an issue with dead_code or unfulfilled_lint_expectations, but the below code does not compile:

#![deny(dead_code, unfulfilled_lint_expectations, reason = "example")]
#![expect(dead_code, reason = "example")]
struct Foo;
impl Foo {}
[zack@laptop foo]$ cargo check
    Checking foo v0.1.0 (/home/zack/projects/foo)
error: this lint expectation is unfulfilled
 --> src/lib.rs:2:11
  |
2 | #![expect(dead_code, reason = "example")]
  |           ^^^^^^^^^
  |
  = note: example
  = note: example
note: the lint level is defined here
 --> src/lib.rs:1:20
  |
1 | #![deny(dead_code, unfulfilled_lint_expectations, reason = "example")]
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `foo` (lib) due to 1 previous error

If you remove impl Foo {}, change expect to allow, or use expect only on Foo (i.e., don't use expect on the crate or mod level); then it compiles. If you remove the expect line altogether, the code doesn't compile showing that dead_code is triggered:

[zack@laptop foo]$ cargo check
    Checking foo v0.1.0 (/home/zack/projects/foo)
error: struct `Foo` is never constructed
 --> src/lib.rs:2:8
  |
2 | struct Foo;
  |        ^^^
  |
  = note: example
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![deny(dead_code, unfulfilled_lint_expectations, reason = "example")]
  |         ^^^^^^^^^

error: could not compile `foo` (lib) due to 1 previous error

The original bug was reported on URLO where the silly empty impl Foo is a Clone impl.

System Info:

[zack@laptop ~]$ rustc -V
rustc 1.94.0 (4a4ef493e 2026-03-02)
[zack@laptop ~]$ uname -a
Linux laptop 6.19.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 14 Mar 2026 01:07:43 +0000 x86_64 GNU/Linux

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions