diff options
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 6 | ||||
| -rw-r--r-- | tests/ui/pattern/unused-parameters-const-pattern.rs | 19 |
2 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index d8e83dc72b0..588ffc16e51 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 00000000000..107c65ddfd3 --- /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<T> Trait for T { + const ASSOC: usize = 10; +} + +fn foo<T>(a: usize) { + match a { + <T as Trait>::ASSOC => (), + _ => (), + } +} + +fn main() {} |
