@@ -16,7 +16,6 @@ use tracing::instrument;
16
16
use super :: { FulfillmentCtxt , NextSolverError } ;
17
17
use crate :: error_reporting:: InferCtxtErrorExt ;
18
18
use crate :: error_reporting:: traits:: OverflowCause ;
19
- use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt ;
20
19
use crate :: traits:: { BoundVarReplacer , PlaceholderReplacer , ScrubbedTraitError } ;
21
20
22
21
/// Deeply normalize all aliases in `value`. This does not handle inference and expects
@@ -143,12 +142,18 @@ where
143
142
144
143
fn normalize_unevaluated_const (
145
144
& mut self ,
146
- uv : ty:: UnevaluatedConst < ' tcx > ,
145
+ alias_ct : ty:: Const < ' tcx > ,
147
146
) -> Result < ty:: Const < ' tcx > , Vec < E > > {
147
+ assert_matches ! ( alias_ct. kind( ) , ty:: ConstKind :: Unevaluated ( ..) ) ;
148
+
148
149
let infcx = self . at . infcx ;
149
150
let tcx = infcx. tcx ;
150
151
let recursion_limit = tcx. recursion_limit ( ) ;
151
152
if !recursion_limit. value_within_limit ( self . depth ) {
153
+ let ty:: ConstKind :: Unevaluated ( uv) = alias_ct. kind ( ) else {
154
+ unreachable ! ( ) ;
155
+ } ;
156
+
152
157
self . at . infcx . err_ctxt ( ) . report_overflow_error (
153
158
OverflowCause :: DeeplyNormalize ( uv. into ( ) ) ,
154
159
self . at . cause . span ,
@@ -164,21 +169,20 @@ where
164
169
tcx,
165
170
self . at . cause . clone ( ) ,
166
171
self . at . param_env ,
167
- ty:: NormalizesTo { alias : uv. into ( ) , term : new_infer_ct. into ( ) } ,
172
+ ty:: PredicateKind :: AliasRelate (
173
+ alias_ct. into ( ) ,
174
+ new_infer_ct. into ( ) ,
175
+ ty:: AliasRelationDirection :: Equate ,
176
+ ) ,
168
177
) ;
169
178
170
- let result = if infcx. predicate_may_hold ( & obligation) {
171
- self . fulfill_cx . register_predicate_obligation ( infcx, obligation) ;
172
- let errors = self . fulfill_cx . select_where_possible ( infcx) ;
173
- if !errors. is_empty ( ) {
174
- return Err ( errors) ;
175
- }
176
- let ct = infcx. resolve_vars_if_possible ( new_infer_ct) ;
177
- ct. try_fold_with ( self ) ?
178
- } else {
179
- ty:: Const :: new_unevaluated ( tcx, uv) . try_super_fold_with ( self ) ?
180
- } ;
179
+ self . fulfill_cx . register_predicate_obligation ( infcx, obligation) ;
180
+ self . select_all_and_stall_coroutine_predicates ( ) ?;
181
181
182
+ // Alias is guaranteed to be fully structurally resolved,
183
+ // so we can super fold here.
184
+ let ct = infcx. resolve_vars_if_possible ( new_infer_ct) ;
185
+ let result = ct. try_super_fold_with ( self ) ?;
182
186
self . depth -= 1 ;
183
187
Ok ( result)
184
188
}
@@ -260,15 +264,12 @@ where
260
264
return Ok ( ct) ;
261
265
}
262
266
263
- let uv = match ct. kind ( ) {
264
- ty:: ConstKind :: Unevaluated ( ct) => ct,
265
- _ => return ct. try_super_fold_with ( self ) ,
266
- } ;
267
+ let ty:: ConstKind :: Unevaluated ( ..) = ct. kind ( ) else { return ct. try_super_fold_with ( self ) } ;
267
268
268
- if uv . has_escaping_bound_vars ( ) {
269
- let ( uv , mapped_regions, mapped_types, mapped_consts) =
270
- BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , uv ) ;
271
- let result = ensure_sufficient_stack ( || self . normalize_unevaluated_const ( uv ) ) ?;
269
+ if ct . has_escaping_bound_vars ( ) {
270
+ let ( ct , mapped_regions, mapped_types, mapped_consts) =
271
+ BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ct ) ;
272
+ let result = ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct ) ) ?;
272
273
Ok ( PlaceholderReplacer :: replace_placeholders (
273
274
infcx,
274
275
mapped_regions,
@@ -278,7 +279,7 @@ where
278
279
result,
279
280
) )
280
281
} else {
281
- ensure_sufficient_stack ( || self . normalize_unevaluated_const ( uv ) )
282
+ ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct ) )
282
283
}
283
284
}
284
285
}
0 commit comments