@@ -3,7 +3,8 @@ use std::cell::RefCell;
33use super :: TraitEngine ;
44use super :: { ChalkFulfillmentContext , FulfillmentContext } ;
55use crate :: infer:: InferCtxtExt ;
6- use rustc_hir:: def_id:: DefId ;
6+ use rustc_data_structures:: fx:: FxHashSet ;
7+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
78use rustc_infer:: infer:: { InferCtxt , InferOk } ;
89use rustc_infer:: traits:: {
910 FulfillmentError , Obligation , ObligationCause , PredicateObligation , TraitEngineExt as _,
@@ -12,6 +13,7 @@ use rustc_middle::ty::error::TypeError;
1213use rustc_middle:: ty:: ToPredicate ;
1314use rustc_middle:: ty:: TypeFoldable ;
1415use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
16+ use rustc_span:: Span ;
1517
1618pub trait TraitEngineExt < ' tcx > {
1719 fn new ( tcx : TyCtxt < ' tcx > ) -> Box < Self > ;
@@ -109,4 +111,23 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
109111 pub fn select_all_or_error ( & self ) -> Vec < FulfillmentError < ' tcx > > {
110112 self . engine . borrow_mut ( ) . select_all_or_error ( self . infcx )
111113 }
114+
115+ pub fn assumed_wf_types (
116+ & self ,
117+ param_env : ty:: ParamEnv < ' tcx > ,
118+ span : Span ,
119+ def_id : LocalDefId ,
120+ ) -> FxHashSet < Ty < ' tcx > > {
121+ let tcx = self . infcx . tcx ;
122+ let assumed_wf_types = tcx. assumed_wf_types ( def_id) ;
123+ let mut implied_bounds = FxHashSet :: default ( ) ;
124+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
125+ let cause = ObligationCause :: misc ( span, hir_id) ;
126+ for ty in assumed_wf_types {
127+ implied_bounds. insert ( ty) ;
128+ let normalized = self . normalize ( cause. clone ( ) , param_env, ty) ;
129+ implied_bounds. insert ( normalized) ;
130+ }
131+ implied_bounds
132+ }
112133}
0 commit comments