@@ -23,14 +23,16 @@ use rustc_hir::intravisit::{self, Visitor};
23
23
use rustc_hir:: { AssocItemKind , ForeignItemKind , ItemId , ItemKind , PatKind } ;
24
24
use rustc_middle:: middle:: privacy:: { EffectiveVisibilities , EffectiveVisibility , Level } ;
25
25
use rustc_middle:: query:: Providers ;
26
- use rustc_middle:: ty:: GenericArgs ;
27
26
use rustc_middle:: ty:: { self , Const , GenericParamDefKind } ;
27
+ use rustc_middle:: ty:: { GenericArgs , ParamEnv } ;
28
28
use rustc_middle:: ty:: { TraitRef , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
29
29
use rustc_middle:: { bug, span_bug} ;
30
30
use rustc_session:: lint;
31
31
use rustc_span:: hygiene:: Transparency ;
32
32
use rustc_span:: symbol:: { kw, sym, Ident } ;
33
33
use rustc_span:: Span ;
34
+ use rustc_trait_selection:: infer:: TyCtxtInferExt ;
35
+ use rustc_trait_selection:: traits:: { ObligationCause , ObligationCtxt } ;
34
36
35
37
use std:: fmt;
36
38
use std:: marker:: PhantomData ;
@@ -1300,15 +1302,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1300
1302
self . in_primary_interface = true ;
1301
1303
let ty = self . tcx . type_of ( self . item_def_id ) . instantiate_identity ( ) ;
1302
1304
1303
- // If `in_assoc_ty`, attempt to normalize `ty`.
1304
- // Ideally, we would normalize in all circumstances, but doing so
1305
- // currently causes some unexpected type errors.
1306
- let maybe_normalized_ty = if self . in_assoc_ty {
1307
- let param_env = self . tcx . param_env ( self . item_def_id ) ;
1308
- self . tcx . try_normalize_erasing_regions ( param_env, ty) . ok ( )
1309
- } else {
1310
- None
1311
- } ;
1305
+ // Attempt to normalize `ty`
1306
+ let param_env = self . tcx . param_env ( self . item_def_id ) ;
1307
+ let maybe_normalized_ty = try_normalize ( self . tcx , param_env, ty) ;
1312
1308
1313
1309
self . visit ( maybe_normalized_ty. unwrap_or ( ty) ) ;
1314
1310
self
@@ -1771,3 +1767,17 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
1771
1767
checker. check_item ( id) ;
1772
1768
}
1773
1769
}
1770
+
1771
+ /// Attempts to deeply normalize `ty`.
1772
+ fn try_normalize < ' tcx > (
1773
+ tcx : TyCtxt < ' tcx > ,
1774
+ param_env : ParamEnv < ' tcx > ,
1775
+ ty : Ty < ' tcx > ,
1776
+ ) -> Result < Ty < ' tcx > , ( ) > {
1777
+ let infcx = tcx. infer_ctxt ( ) . with_next_trait_solver ( true ) . build ( ) ;
1778
+ let ocx = ObligationCtxt :: new ( & infcx) ;
1779
+ let cause = ObligationCause :: dummy ( ) ;
1780
+ let Ok ( ty) = ocx. deeply_normalize ( & cause, param_env, ty) else { return Err ( ( ) ) } ;
1781
+ let errors = ocx. select_all_or_error ( ) ;
1782
+ if errors. is_empty ( ) { Ok ( ty) } else { Err ( ( ) ) }
1783
+ }
0 commit comments