@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
8
8
use rustc_infer:: traits:: TraitEngineExt ;
9
9
use rustc_infer:: traits:: { FulfillmentError , Obligation , TraitEngine } ;
10
10
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
11
- use rustc_middle:: traits:: { ObligationCause , Reveal } ;
11
+ use rustc_middle:: traits:: ObligationCause ;
12
12
use rustc_middle:: ty:: { self , AliasTy , Ty , TyCtxt , UniverseIndex } ;
13
13
use rustc_middle:: ty:: { FallibleTypeFolder , TypeFolder , TypeSuperFoldable } ;
14
14
use rustc_middle:: ty:: { TypeFoldable , TypeVisitableExt } ;
@@ -52,14 +52,16 @@ struct NormalizationFolder<'me, 'tcx> {
52
52
impl < ' tcx > NormalizationFolder < ' _ , ' tcx > {
53
53
fn normalize_alias_ty (
54
54
& mut self ,
55
- alias : AliasTy < ' tcx > ,
55
+ alias_ty : Ty < ' tcx > ,
56
56
) -> Result < Ty < ' tcx > , Vec < FulfillmentError < ' tcx > > > {
57
+ assert ! ( matches!( alias_ty. kind( ) , ty:: Alias ( ..) ) ) ;
58
+
57
59
let infcx = self . at . infcx ;
58
60
let tcx = infcx. tcx ;
59
61
let recursion_limit = tcx. recursion_limit ( ) ;
60
62
if !recursion_limit. value_within_limit ( self . depth ) {
61
63
self . at . infcx . err_ctxt ( ) . report_overflow_error (
62
- & alias . to_ty ( tcx ) ,
64
+ & alias_ty ,
63
65
self . at . cause . span ,
64
66
true ,
65
67
|_| { } ,
@@ -76,7 +78,11 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
76
78
tcx,
77
79
self . at . cause . clone ( ) ,
78
80
self . at . param_env ,
79
- ty:: NormalizesTo { alias, term : new_infer_ty. into ( ) } ,
81
+ ty:: PredicateKind :: AliasRelate (
82
+ alias_ty. into ( ) ,
83
+ new_infer_ty. into ( ) ,
84
+ ty:: AliasRelationDirection :: Equate ,
85
+ ) ,
80
86
) ;
81
87
82
88
// Do not emit an error if normalization is known to fail but instead
@@ -90,9 +96,12 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
90
96
return Err ( errors) ;
91
97
}
92
98
let ty = infcx. resolve_vars_if_possible ( new_infer_ty) ;
93
- ty. try_fold_with ( self ) ?
99
+
100
+ // Alias is guaranteed to be fully structurally resolved,
101
+ // so we can super fold here.
102
+ ty. try_super_fold_with ( self ) ?
94
103
} else {
95
- alias . to_ty ( tcx ) . try_super_fold_with ( self ) ?
104
+ alias_ty . try_super_fold_with ( self ) ?
96
105
} ;
97
106
98
107
self . depth -= 1 ;
@@ -170,24 +179,18 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
170
179
}
171
180
172
181
fn try_fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
173
- let reveal = self . at . param_env . reveal ( ) ;
174
182
let infcx = self . at . infcx ;
175
183
debug_assert_eq ! ( ty, infcx. shallow_resolve( ty) ) ;
176
- if !needs_normalization ( & ty , reveal ) {
184
+ if !ty . has_projections ( ) {
177
185
return Ok ( ty) ;
178
186
}
179
187
180
- // We don't normalize opaque types unless we have
181
- // `Reveal::All`, even if we're in the defining scope.
182
- let data = match * ty. kind ( ) {
183
- ty:: Alias ( kind, alias_ty) if kind != ty:: Opaque || reveal == Reveal :: All => alias_ty,
184
- _ => return ty. try_super_fold_with ( self ) ,
185
- } ;
188
+ let ty:: Alias ( ..) = * ty. kind ( ) else { return ty. try_super_fold_with ( self ) } ;
186
189
187
- if data . has_escaping_bound_vars ( ) {
188
- let ( data , mapped_regions, mapped_types, mapped_consts) =
189
- BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , data ) ;
190
- let result = ensure_sufficient_stack ( || self . normalize_alias_ty ( data ) ) ?;
190
+ if ty . has_escaping_bound_vars ( ) {
191
+ let ( ty , mapped_regions, mapped_types, mapped_consts) =
192
+ BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ty ) ;
193
+ let result = ensure_sufficient_stack ( || self . normalize_alias_ty ( ty ) ) ?;
191
194
Ok ( PlaceholderReplacer :: replace_placeholders (
192
195
infcx,
193
196
mapped_regions,
@@ -197,7 +200,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
197
200
result,
198
201
) )
199
202
} else {
200
- ensure_sufficient_stack ( || self . normalize_alias_ty ( data ) )
203
+ ensure_sufficient_stack ( || self . normalize_alias_ty ( ty ) )
201
204
}
202
205
}
203
206
0 commit comments