-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsL-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Description
Code
#[allow(dead_code)]
trait Foo {
const FOO: u32;
}
impl Foo for u32 {
const FOO: u32 = roundtrip(0);
}
const fn roundtrip(x: u32) -> u32 {
x
}
Current output
warning: function `foo` is never used
--> src/lib.rs:10:10
|
10 | const fn foo(x: u32) -> u32 {
| ^^^
|
= note: `#[warn(dead_code)]` on by default
Desired output
No lint
Rationale and extra context
roundtrip
is used in an instance of trait Foo
so it isn't dead. Foo
isn't used, but with it being allow
ed I don't think the check should propagate back elsewhere.
E.g. bar
doesn't get a lint in this case:
#[allow(dead_code)]
const X: u32 = bar(0);
const fn bar(x: u32) -> u32 {
x
}
This regressed in #143519, cc @mu001999
Rust Version
searched nightlies: from nightly-2025-05-31 to nightly-2025-07-15
regressed nightly: nightly-2025-07-14
searched commit range: bfc046a...e9182f1
regressed commit: 56835d7
bisected with cargo-bisect-rustc v0.6.10
Host triple: aarch64-apple-darwin
Reproduce with:
cargo bisect-rustc --start 2025-05-31 --end 2025-07-15 --without-cargo --script=rustc -- a.rs
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsL-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.