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,27 @@ 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 ! ( ) ;
106
+ let term = match alias_term. kind ( ) {
107
+ ty:: TermKind :: Ty ( ty) => match * ty. kind ( ) {
108
+ ty:: Alias ( _, alias) => alias. into ( ) ,
109
+ _ => unreachable ! ( ) ,
110
+ } ,
111
+ ty:: TermKind :: Const ( ct) => match ct. kind ( ) {
112
+ ty:: ConstKind :: Unevaluated ( alias) => alias. into ( ) ,
113
+ _ => unreachable ! ( ) ,
114
+ } ,
155
115
} ;
156
116
157
117
self . at . infcx . err_ctxt ( ) . report_overflow_error (
158
- OverflowCause :: DeeplyNormalize ( uv . into ( ) ) ,
118
+ OverflowCause :: DeeplyNormalize ( term ) ,
159
119
self . at . cause . span ,
160
120
true ,
161
121
|_| { } ,
@@ -164,14 +124,14 @@ where
164
124
165
125
self . depth += 1 ;
166
126
167
- let new_infer_ct = infcx. next_const_var ( self . at . cause . span ) ;
127
+ let infer_term = infcx. next_term_var_of_kind ( alias_term , self . at . cause . span ) ;
168
128
let obligation = Obligation :: new (
169
129
tcx,
170
130
self . at . cause . clone ( ) ,
171
131
self . at . param_env ,
172
132
ty:: PredicateKind :: AliasRelate (
173
- alias_ct . into ( ) ,
174
- new_infer_ct . into ( ) ,
133
+ alias_term . into ( ) ,
134
+ infer_term . into ( ) ,
175
135
ty:: AliasRelationDirection :: Equate ,
176
136
) ,
177
137
) ;
@@ -181,8 +141,11 @@ where
181
141
182
142
// Alias is guaranteed to be fully structurally resolved,
183
143
// 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 ) ?;
144
+ let term = infcx. resolve_vars_if_possible ( infer_term) ;
145
+ let result = match term. kind ( ) {
146
+ ty:: TermKind :: Ty ( ty) => ty. try_super_fold_with ( self ) ?. into ( ) ,
147
+ ty:: TermKind :: Const ( ct) => ct. try_super_fold_with ( self ) ?. into ( ) ,
148
+ } ;
186
149
self . depth -= 1 ;
187
150
Ok ( result)
188
151
}
@@ -242,7 +205,8 @@ where
242
205
if ty. has_escaping_bound_vars ( ) {
243
206
let ( ty, mapped_regions, mapped_types, mapped_consts) =
244
207
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ty) ;
245
- let result = ensure_sufficient_stack ( || self . normalize_alias_ty ( ty) ) ?;
208
+ let result =
209
+ ensure_sufficient_stack ( || self . normalize_alias_term ( ty. into ( ) ) ) ?. expect_type ( ) ;
246
210
Ok ( PlaceholderReplacer :: replace_placeholders (
247
211
infcx,
248
212
mapped_regions,
@@ -252,7 +216,7 @@ where
252
216
result,
253
217
) )
254
218
} else {
255
- ensure_sufficient_stack ( || self . normalize_alias_ty ( ty) )
219
+ Ok ( ensure_sufficient_stack ( || self . normalize_alias_term ( ty. into ( ) ) ) ? . expect_type ( ) )
256
220
}
257
221
}
258
222
@@ -269,7 +233,8 @@ where
269
233
if ct. has_escaping_bound_vars ( ) {
270
234
let ( ct, mapped_regions, mapped_types, mapped_consts) =
271
235
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ct) ;
272
- let result = ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct) ) ?;
236
+ let result =
237
+ ensure_sufficient_stack ( || self . normalize_alias_term ( ct. into ( ) ) ) ?. expect_const ( ) ;
273
238
Ok ( PlaceholderReplacer :: replace_placeholders (
274
239
infcx,
275
240
mapped_regions,
@@ -279,7 +244,7 @@ where
279
244
result,
280
245
) )
281
246
} else {
282
- ensure_sufficient_stack ( || self . normalize_unevaluated_const ( ct) )
247
+ Ok ( ensure_sufficient_stack ( || self . normalize_alias_term ( ct. into ( ) ) ) ? . expect_const ( ) )
283
248
}
284
249
}
285
250
}
0 commit comments