@@ -23,14 +23,16 @@ use rustc_hir::{AssocItemKind, ForeignItemKind, ItemId, ItemKind, PatKind};
2323use rustc_middle:: middle:: privacy:: { EffectiveVisibilities , EffectiveVisibility , Level } ;
2424use rustc_middle:: query:: Providers ;
2525use rustc_middle:: ty:: print:: PrintTraitRefExt as _;
26- use rustc_middle:: ty:: GenericArgs ;
2726use rustc_middle:: ty:: { self , Const , GenericParamDefKind } ;
27+ use rustc_middle:: ty:: { GenericArgs , ParamEnv } ;
2828use rustc_middle:: ty:: { TraitRef , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
2929use rustc_middle:: { bug, span_bug} ;
3030use rustc_session:: lint;
3131use rustc_span:: hygiene:: Transparency ;
3232use rustc_span:: symbol:: { kw, sym, Ident } ;
3333use rustc_span:: Span ;
34+ use rustc_trait_selection:: infer:: TyCtxtInferExt ;
35+ use rustc_trait_selection:: traits:: { ObligationCause , ObligationCtxt } ;
3436use tracing:: debug;
3537
3638use std:: fmt;
@@ -1304,15 +1306,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13041306 self . in_primary_interface = true ;
13051307 let ty = self . tcx . type_of ( self . item_def_id ) . instantiate_identity ( ) ;
13061308
1307- // If `in_assoc_ty`, attempt to normalize `ty`.
1308- // Ideally, we would normalize in all circumstances, but doing so
1309- // currently causes some unexpected type errors.
1310- let maybe_normalized_ty = if self . in_assoc_ty {
1311- let param_env = self . tcx . param_env ( self . item_def_id ) ;
1312- self . tcx . try_normalize_erasing_regions ( param_env, ty) . ok ( )
1313- } else {
1314- None
1315- } ;
1309+ // Attempt to normalize `ty`
1310+ let param_env = self . tcx . param_env ( self . item_def_id ) ;
1311+ let maybe_normalized_ty = try_normalize ( self . tcx , param_env, ty) ;
13161312
13171313 self . visit ( maybe_normalized_ty. unwrap_or ( ty) ) ;
13181314 self
@@ -1775,3 +1771,17 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
17751771 checker. check_item ( id) ;
17761772 }
17771773}
1774+
1775+ /// Attempts to deeply normalize `ty`.
1776+ fn try_normalize < ' tcx > (
1777+ tcx : TyCtxt < ' tcx > ,
1778+ param_env : ParamEnv < ' tcx > ,
1779+ ty : Ty < ' tcx > ,
1780+ ) -> Result < Ty < ' tcx > , ( ) > {
1781+ let infcx = tcx. infer_ctxt ( ) . with_next_trait_solver ( true ) . build ( ) ;
1782+ let ocx = ObligationCtxt :: new ( & infcx) ;
1783+ let cause = ObligationCause :: dummy ( ) ;
1784+ let Ok ( ty) = ocx. deeply_normalize ( & cause, param_env, ty) else { return Err ( ( ) ) } ;
1785+ let errors = ocx. select_all_or_error ( ) ;
1786+ if errors. is_empty ( ) { Ok ( ty) } else { Err ( ( ) ) }
1787+ }
0 commit comments