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