@@ -23,14 +23,16 @@ use rustc_hir::{AssocItemKind, ForeignItemKind, ItemId, ItemKind, PatKind};
23
23
use rustc_middle:: middle:: privacy:: { EffectiveVisibilities , EffectiveVisibility , Level } ;
24
24
use rustc_middle:: query:: Providers ;
25
25
use rustc_middle:: ty:: print:: PrintTraitRefExt as _;
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
use tracing:: debug;
35
37
36
38
use std:: fmt;
@@ -1304,15 +1306,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1304
1306
self . in_primary_interface = true ;
1305
1307
let ty = self . tcx . type_of ( self . item_def_id ) . instantiate_identity ( ) ;
1306
1308
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) ;
1316
1312
1317
1313
self . visit ( maybe_normalized_ty. unwrap_or ( ty) ) ;
1318
1314
self
@@ -1775,3 +1771,17 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
1775
1771
checker. check_item ( id) ;
1776
1772
}
1777
1773
}
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