11use crate :: traits:: error_reporting:: TypeErrCtxtExt ;
22use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt ;
3- use crate :: traits:: { needs_normalization, TraitEngineExt as _} ;
4- use crate :: traits:: { BoundVarReplacer , PlaceholderReplacer } ;
3+ use crate :: traits:: { needs_normalization, BoundVarReplacer , PlaceholderReplacer } ;
54use rustc_data_structures:: stack:: ensure_sufficient_stack;
65use rustc_infer:: infer:: at:: At ;
76use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
@@ -13,22 +12,23 @@ use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
1312use rustc_middle:: ty:: { FallibleTypeFolder , TypeSuperFoldable } ;
1413use rustc_middle:: ty:: { TypeFoldable , TypeVisitableExt } ;
1514
15+ use super :: FulfillmentCtxt ;
16+
1617/// Deeply normalize all aliases in `value`. This does not handle inference and expects
1718/// its input to be already fully resolved.
1819pub ( crate ) fn deeply_normalize < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > (
1920 at : At < ' _ , ' tcx > ,
2021 value : T ,
2122) -> Result < T , Vec < FulfillmentError < ' tcx > > > {
22- let mut fulfill_cx = <dyn TraitEngine < ' tcx > >:: new ( & at. infcx ) ;
23- let mut folder =
24- NormalizationFolder { at, fulfill_cx : & mut * fulfill_cx, depth : 0 , universes : Vec :: new ( ) } ;
23+ let fulfill_cx = FulfillmentCtxt :: new ( ) ;
24+ let mut folder = NormalizationFolder { at, fulfill_cx, depth : 0 , universes : Vec :: new ( ) } ;
2525
2626 value. try_fold_with ( & mut folder)
2727}
2828
2929struct NormalizationFolder < ' me , ' tcx > {
3030 at : At < ' me , ' tcx > ,
31- fulfill_cx : & ' me mut dyn TraitEngine < ' tcx > ,
31+ fulfill_cx : FulfillmentCtxt < ' tcx > ,
3232 depth : usize ,
3333 universes : Vec < Option < UniverseIndex > > ,
3434}
@@ -163,16 +163,14 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
163163 return Ok ( ty) ;
164164 }
165165
166- let ( kind, data) = match * ty. kind ( ) {
167- ty:: Alias ( kind, alias_ty) => ( kind, alias_ty) ,
168- _ => return ty. try_super_fold_with ( self ) ,
169- } ;
170-
171166 // We don't normalize opaque types unless we have
172167 // `Reveal::All`, even if we're in the defining scope.
173- if matches ! ( kind, ty:: Opaque ) && reveal == Reveal :: UserFacing {
174- return ty. try_super_fold_with ( self ) ;
175- }
168+ let data = match * ty. kind ( ) {
169+ ty:: Alias ( kind, alias_ty) if kind != ty:: Opaque || reveal == Reveal :: UserFacing => {
170+ alias_ty
171+ }
172+ _ => return ty. try_super_fold_with ( self ) ,
173+ } ;
176174
177175 if data. has_escaping_bound_vars ( ) {
178176 let ( data, mapped_regions, mapped_types, mapped_consts) =
0 commit comments