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