@@ -39,6 +39,8 @@ use rustc_session::lint;
3939use rustc_span:: hygiene:: Transparency ;
4040use rustc_span:: symbol:: { kw, sym, Ident } ;
4141use rustc_span:: Span ;
42+ use rustc_trait_selection:: infer:: TyCtxtInferExt ;
43+ use rustc_trait_selection:: traits:: { ObligationCause , ObligationCtxt } ;
4244use tracing:: debug;
4345use { rustc_attr as attr, rustc_hir as hir} ;
4446
@@ -1307,15 +1309,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13071309 self . in_primary_interface = true ;
13081310 let ty = self . tcx . type_of ( self . item_def_id ) . instantiate_identity ( ) ;
13091311
1310- // If `in_assoc_ty`, attempt to normalize `ty`.
1311- // Ideally, we would normalize in all circumstances, but doing so
1312- // currently causes some unexpected type errors.
1313- let maybe_normalized_ty = if self . in_assoc_ty {
1314- let param_env = self . tcx . param_env ( self . item_def_id ) ;
1315- self . tcx . try_normalize_erasing_regions ( param_env, ty) . ok ( )
1316- } else {
1317- None
1318- } ;
1312+ // Attempt to normalize `ty`
1313+ let param_env = self . tcx . param_env ( self . item_def_id ) ;
1314+ let maybe_normalized_ty = try_normalize ( self . tcx , param_env, ty) ;
13191315
13201316 self . visit ( maybe_normalized_ty. unwrap_or ( ty) ) ;
13211317 self
@@ -1778,3 +1774,17 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
17781774 checker. check_item ( id) ;
17791775 }
17801776}
1777+
1778+ /// Attempts to deeply normalize `ty`.
1779+ fn try_normalize < ' tcx > (
1780+ tcx : TyCtxt < ' tcx > ,
1781+ param_env : ty:: ParamEnv < ' tcx > ,
1782+ ty : Ty < ' tcx > ,
1783+ ) -> Result < Ty < ' tcx > , ( ) > {
1784+ let infcx = tcx. infer_ctxt ( ) . with_next_trait_solver ( true ) . build ( ) ;
1785+ let ocx = ObligationCtxt :: new ( & infcx) ;
1786+ let cause = ObligationCause :: dummy ( ) ;
1787+ let Ok ( ty) = ocx. deeply_normalize ( & cause, param_env, ty) else { return Err ( ( ) ) } ;
1788+ let errors = ocx. select_all_or_error ( ) ;
1789+ if errors. is_empty ( ) { Ok ( ty) } else { Err ( ( ) ) }
1790+ }
0 commit comments