-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-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.
Description
Ran into this warning and wanted to share my confusion with it. My confusion stems from the fact that this warning seems to be triggered inconsistently. Example of this
pub struct Example<const CONSTANT: u32>; impl<const CONSTANT: u32> Example<CONSTANT> { const DOESNT_CHANGE: usize = 3; const ALSO_DOESNT_CHANGE: usize = Self::DOESNT_CHANGE; pub fn does_trigger_warning(&self, i: usize) -> usize { match i { Self::ALSO_DOESNT_CHANGE => 0, _ => 1 } } pub fn doesnt_trigger_warning(&self, i: usize) -> usize { match i { Self::DOESNT_CHANGE => 0, _ => 1 } } pub fn also_doesnt_trigger_warning(&self, i: usize) -> usize { if i == Self::ALSO_DOESNT_CHANGE { 0 } else { 1 } } }The other thing that I found confusing was that the warning shows up on the declaration of
DOESNT_CHANGE
and not the usage (which is what caused the warning to appear).I am using
cargo 1.88.0-nightly (d811228b1 2025-04-15)
andrustc 1.88.0-nightly (077cedc2a 2025-04-19)
.
Originally posted by @MorganBennetDev in #76200
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-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.