File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
compiler/rustc_trait_selection/src/traits Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -625,6 +625,12 @@ pub fn try_evaluate_const<'tcx>(
625625 // So we are free to simply defer evaluation here.
626626 //
627627 // FIXME: This assumes that `args` are normalized which is not necessarily true
628+ //
629+ // Const patterns are converted to type system constants before being
630+ // evaluated. However, we don't care about them here as pattern evaluation
631+ // logic does not go through type system normalization. If it did this would
632+ // be a backwards compatibility problem as we do not enforce "syntactic" non-
633+ // usage of generic parameters like we do here.
628634 if uv. args . has_non_region_param ( ) || uv. args . has_non_region_infer ( ) {
629635 return Err ( EvaluateConstErr :: HasGenericsOrInfers ) ;
630636 }
Original file line number Diff line number Diff line change 1+ //@ check-pass
2+
3+ // Tests that const patterns that use generic parameters are
4+ // allowed if we are still able to evaluate them.
5+
6+ trait Trait { const ASSOC : usize ; }
7+
8+ impl < T > Trait for T {
9+ const ASSOC : usize = 10 ;
10+ }
11+
12+ fn foo < T > ( a : usize ) {
13+ match a {
14+ <T as Trait >:: ASSOC => ( ) ,
15+ _ => ( ) ,
16+ }
17+ }
18+
19+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments