File tree 1 file changed +23
-2
lines changed
compiler/rustc_trait_selection/src/traits
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -37,13 +37,17 @@ pub fn is_const_evaluatable<'tcx>(
37
37
| ty:: ConstKind :: Value ( _, _)
38
38
| ty:: ConstKind :: Error ( _) => return Ok ( ( ) ) ,
39
39
ty:: ConstKind :: Infer ( _) => return Err ( NotConstEvaluatable :: MentionsInfer ) ,
40
- } ;
40
+ }
41
41
42
42
if tcx. features ( ) . generic_const_exprs {
43
43
let ct = tcx. expand_abstract_consts ( unexpanded_ct) ;
44
44
45
+ if trivially_satisfied_from_param_env ( ct, param_env) {
46
+ return Ok ( ( ) ) ;
47
+ }
48
+
45
49
let is_anon_ct = if let ty:: ConstKind :: Unevaluated ( uv) = ct. kind ( ) {
46
- tcx. def_kind ( uv. def ) == DefKind :: AnonConst
50
+ matches ! ( tcx. def_kind( uv. def) , DefKind :: AnonConst )
47
51
} else {
48
52
false
49
53
} ;
@@ -150,6 +154,23 @@ pub fn is_const_evaluatable<'tcx>(
150
154
}
151
155
}
152
156
157
+ fn trivially_satisfied_from_param_env < ' tcx > (
158
+ ct : ty:: Const < ' tcx > ,
159
+ param_env : ty:: ParamEnv < ' tcx > ,
160
+ ) -> bool {
161
+ for pred in param_env. caller_bounds ( ) {
162
+ if let ty:: ClauseKind :: ConstEvaluatable ( ce) = pred. kind ( ) . skip_binder ( ) {
163
+ if let ty:: ConstKind :: Unevaluated ( uv_env) = ce. kind ( )
164
+ && let ty:: ConstKind :: Unevaluated ( uv) = ct. kind ( )
165
+ && uv == uv_env
166
+ {
167
+ return true ;
168
+ }
169
+ }
170
+ }
171
+ false
172
+ }
173
+
153
174
#[ instrument( skip( infcx, tcx) , level = "debug" ) ]
154
175
fn satisfied_from_param_env < ' tcx > (
155
176
tcx : TyCtxt < ' tcx > ,
You can’t perform that action at this time.
0 commit comments