@@ -11,7 +11,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1111use tracing:: { debug, instrument} ;
1212
1313use crate :: traits:: query:: NoSolution ;
14- use crate :: ty:: fold:: { FallibleTypeFolder , TypeFoldable , TypeFolder } ;
14+ use crate :: ty:: fold:: { FallibleTypeFolder , TypeFoldable , TypeFolder , TypeSuperFoldable } ;
1515use crate :: ty:: { self , EarlyBinder , GenericArgsRef , Ty , TyCtxt , TypeVisitableExt } ;
1616
1717#[ derive( Debug , Copy , Clone , HashStable , TyEncodable , TyDecodable ) ]
@@ -222,16 +222,27 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for TryNormalizeAfterErasingRegionsF
222222 }
223223
224224 fn try_fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
225- match self . try_normalize_generic_arg_after_erasing_regions ( ty. into ( ) ) {
226- Ok ( t) => Ok ( t. expect_ty ( ) ) ,
227- Err ( _) => Err ( NormalizationError :: Type ( ty) ) ,
225+ // HACKY HACK: dont walk into binders
226+ if let ty:: Alias ( ..) | ty:: Dynamic ( ..) | ty:: FnPtr ( ..) = ty. kind ( ) {
227+ self . try_normalize_generic_arg_after_erasing_regions ( ty. into ( ) )
228+ . map ( |arg| arg. expect_ty ( ) )
229+ . map_err ( |_| NormalizationError :: Type ( ty) )
230+ } else if ty. has_aliases ( ) {
231+ ty. try_super_fold_with ( self )
232+ } else {
233+ Ok ( ty)
228234 }
229235 }
230236
231- fn try_fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> Result < ty:: Const < ' tcx > , Self :: Error > {
232- match self . try_normalize_generic_arg_after_erasing_regions ( c. into ( ) ) {
233- Ok ( t) => Ok ( t. expect_const ( ) ) ,
234- Err ( _) => Err ( NormalizationError :: Const ( c) ) ,
237+ fn try_fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> Result < ty:: Const < ' tcx > , Self :: Error > {
238+ if let ty:: ConstKind :: Unevaluated ( ..) = ct. kind ( ) {
239+ self . try_normalize_generic_arg_after_erasing_regions ( ct. into ( ) )
240+ . map ( |arg| arg. expect_const ( ) )
241+ . map_err ( |_| NormalizationError :: Const ( ct) )
242+ } else if ct. has_aliases ( ) {
243+ ct. try_super_fold_with ( self )
244+ } else {
245+ Ok ( ct)
235246 }
236247 }
237248}
0 commit comments