1
- use std:: assert_matches:: assert_matches;
2
1
use std:: fmt:: Debug ;
3
2
4
3
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -96,66 +95,18 @@ impl<'tcx, E> NormalizationFolder<'_, 'tcx, E>
96
95
where
97
96
E : FromSolverError < ' tcx , NextSolverError < ' tcx > > ,
98
97
{
99
- fn normalize_alias_ty ( & mut self , alias_ty : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Vec < E > > {
100
- assert_matches ! ( alias_ty. kind( ) , ty:: Alias ( ..) ) ;
101
-
102
- let infcx = self . at . infcx ;
103
- let tcx = infcx. tcx ;
104
- let recursion_limit = tcx. recursion_limit ( ) ;
105
- if !recursion_limit. value_within_limit ( self . depth ) {
106
- let ty:: Alias ( _, data) = * alias_ty. kind ( ) else {
107
- unreachable ! ( ) ;
108
- } ;
109
-
110
- self . at . infcx . err_ctxt ( ) . report_overflow_error (
111
- OverflowCause :: DeeplyNormalize ( data. into ( ) ) ,
112
- self . at . cause . span ,
113
- true ,
114
- |_| { } ,
115
- ) ;
116
- }
117
-
118
- self . depth += 1 ;
119
-
120
- let new_infer_ty = infcx. next_ty_var ( self . at . cause . span ) ;
121
- let obligation = Obligation :: new (
122
- tcx,
123
- self . at . cause . clone ( ) ,
124
- self . at . param_env ,
125
- ty:: PredicateKind :: AliasRelate (
126
- alias_ty. into ( ) ,
127
- new_infer_ty. into ( ) ,
128
- ty:: AliasRelationDirection :: Equate ,
129
- ) ,
130
- ) ;
131
-
132
- self . fulfill_cx . register_predicate_obligation ( infcx, obligation) ;
133
- self . select_all_and_stall_coroutine_predicates ( ) ?;
134
-
135
- // Alias is guaranteed to be fully structurally resolved,
136
- // so we can super fold here.
137
- let ty = infcx. resolve_vars_if_possible ( new_infer_ty) ;
138
- let result = ty. try_super_fold_with ( self ) ?;
139
- self . depth -= 1 ;
140
- Ok ( result)
141
- }
142
-
143
- fn normalize_unevaluated_const (
98
+ fn normalize_alias_term (
144
99
& mut self ,
145
- alias_ct : ty:: Const < ' tcx > ,
146
- ) -> Result < ty:: Const < ' tcx > , Vec < E > > {
147
- assert_matches ! ( alias_ct. kind( ) , ty:: ConstKind :: Unevaluated ( ..) ) ;
148
-
100
+ alias_term : ty:: Term < ' tcx > ,
101
+ ) -> Result < ty:: Term < ' tcx > , Vec < E > > {
149
102
let infcx = self . at . infcx ;
150
103
let tcx = infcx. tcx ;
151
104
let recursion_limit = tcx. recursion_limit ( ) ;
152
105
if !recursion_limit. value_within_limit ( self . depth ) {
153
- let ty:: ConstKind :: Unevaluated ( uv) = alias_ct. kind ( ) else {
154
- unreachable ! ( ) ;
155
- } ;
106
+ let term = alias_term. to_alias_term ( ) . unwrap ( ) ;
156
107
157
108
self . at . infcx . err_ctxt ( ) . report_overflow_error (
158
- OverflowCause :: DeeplyNormalize ( uv . into ( ) ) ,
109
+ OverflowCause :: DeeplyNormalize ( term ) ,
159
110
self . at . cause . span ,
160
111
true ,
161
112
|_| { } ,
@@ -164,14 +115,14 @@ where
164
115
165
116
self . depth += 1 ;
166
117
167
- let new_infer_ct = infcx. next_const_var ( self . at . cause . span ) ;
118
+ let infer_term = infcx. next_term_var_of_kind ( alias_term , self . at . cause . span ) ;
168
119
let obligation = Obligation :: new (
169
120
tcx,
170
121
self . at . cause . clone ( ) ,
171
122
self . at . param_env ,
172
123
ty:: PredicateKind :: AliasRelate (
173
- alias_ct . into ( ) ,
174
- new_infer_ct . into ( ) ,
124
+ alias_term . into ( ) ,
125
+ infer_term . into ( ) ,
175
126
ty:: AliasRelationDirection :: Equate ,
176
127
) ,
177
128
) ;
@@ -181,8 +132,13 @@ where
181
132
182
133
// Alias is guaranteed to be fully structurally resolved,
183
134
// 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 ) ?;
135
+ let term = infcx. resolve_vars_if_possible ( infer_term) ;
136
+ // super-folding the `term` will directly fold the `Ty` or `Const` so
137
+ // we have to match on the term and super-fold them manually.
138
+ let result = match term. kind ( ) {
139
+ ty:: TermKind :: Ty ( ty) => ty. try_super_fold_with ( self ) ?. into ( ) ,
140
+ ty:: TermKind :: Const ( ct) => ct. try_super_fold_with ( self ) ?. into ( ) ,
141
+ } ;
186
142
self . depth -= 1 ;
187
143
Ok ( result)
188
144
}
@@ -242,7 +198,8 @@ where
242
198
if ty. has_escaping_bound_vars ( ) {
243
199
let ( ty, mapped_regions, mapped_types, mapped_consts) =
244
200
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ty) ;
245
- let result = ensure_sufficient_stack ( || self . normalize_alias_ty ( ty) ) ?;
201
+ let result =
202
+ ensure_sufficient_stack ( || self . normalize_alias_term ( ty. into ( ) ) ) ?. expect_type ( ) ;
246
203
Ok ( PlaceholderReplacer :: replace_placeholders (
247
204
infcx,
248
205
mapped_regions,
@@ -252,7 +209,7 @@ where
252
209
result,
253
210
) )
254
211
} else {
255
- ensure_sufficient_stack ( || self . normalize_alias_ty ( ty) )
212
+ Ok ( ensure_sufficient_stack ( || self . normalize_alias_term ( ty. into ( ) ) ) ? . expect_type ( ) )
256
213
}
257
214
}
258
215
@@ -269,7 +226,8 @@ where
269
226
if ct. has_escaping_bound_vars ( ) {
270
227
let ( ct, mapped_regions, mapped_types, mapped_consts) =
271
228
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ct) ;
272
- let result = ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct) ) ?;
229
+ let result =
230
+ ensure_sufficient_stack ( || self . normalize_alias_term ( ct. into ( ) ) ) ?. expect_const ( ) ;
273
231
Ok ( PlaceholderReplacer :: replace_placeholders (
274
232
infcx,
275
233
mapped_regions,
@@ -279,7 +237,7 @@ where
279
237
result,
280
238
) )
281
239
} else {
282
- ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct) )
240
+ Ok ( ensure_sufficient_stack ( || self . normalize_alias_term ( ct. into ( ) ) ) ? . expect_const ( ) )
283
241
}
284
242
}
285
243
}
0 commit comments