Skip to content

const_evaluatable_unchecked FCW applies to all kinds of const evaluation not just of repeat expr const args #140447

@BoxyUwU

Description

@BoxyUwU

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) and rustc 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, ...)A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions