Add test/comment about const patterns with unused params

This commit is contained in:
Boxy 2025-05-22 12:52:46 +01:00
parent 217c4ad427
commit fdccb42167
2 changed files with 25 additions and 0 deletions

View file

@ -625,6 +625,12 @@ pub fn try_evaluate_const<'tcx>(
// So we are free to simply defer evaluation here.
//
// FIXME: This assumes that `args` are normalized which is not necessarily true
//
// Const patterns are converted to type system constants before being
// evaluated. However, we don't care about them here as pattern evaluation
// logic does not go through type system normalization. If it did this would
// be a backwards compatibility problem as we do not enforce "syntactic" non-
// usage of generic parameters like we do here.
if uv.args.has_non_region_param() || uv.args.has_non_region_infer() {
return Err(EvaluateConstErr::HasGenericsOrInfers);
}

View file

@ -0,0 +1,19 @@
//@ check-pass
// Tests that const patterns that use generic parameters are
// allowed if we are still able to evaluate them.
trait Trait { const ASSOC: usize; }
impl<T> Trait for T {
const ASSOC: usize = 10;
}
fn foo<T>(a: usize) {
match a {
<T as Trait>::ASSOC => (),
_ => (),
}
}
fn main() {}