@@ -39,6 +39,8 @@ use rustc_session::lint;
39
39
use rustc_span:: hygiene:: Transparency ;
40
40
use rustc_span:: symbol:: { kw, sym, Ident } ;
41
41
use rustc_span:: Span ;
42
+ use rustc_trait_selection:: infer:: TyCtxtInferExt ;
43
+ use rustc_trait_selection:: traits:: { ObligationCause , ObligationCtxt } ;
42
44
use tracing:: debug;
43
45
use { rustc_attr as attr, rustc_hir as hir} ;
44
46
@@ -1307,15 +1309,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1307
1309
self . in_primary_interface = true ;
1308
1310
let ty = self . tcx . type_of ( self . item_def_id ) . instantiate_identity ( ) ;
1309
1311
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) ;
1319
1315
1320
1316
self . visit ( maybe_normalized_ty. unwrap_or ( ty) ) ;
1321
1317
self
@@ -1778,3 +1774,17 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
1778
1774
checker. check_item ( id) ;
1779
1775
}
1780
1776
}
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