diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index d8e83dc72b02..588ffc16e510 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -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); } diff --git a/tests/ui/pattern/unused-parameters-const-pattern.rs b/tests/ui/pattern/unused-parameters-const-pattern.rs new file mode 100644 index 000000000000..107c65ddfd3a --- /dev/null +++ b/tests/ui/pattern/unused-parameters-const-pattern.rs @@ -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 Trait for T { + const ASSOC: usize = 10; +} + +fn foo(a: usize) { + match a { + ::ASSOC => (), + _ => (), + } +} + +fn main() {}