22
33use rustc_data_structures:: fx:: FxHashSet ;
44use rustc_index:: bit_set:: BitSet ;
5- use rustc_infer:: infer:: { DefiningAnchor , TyCtxtInferExt } ;
6- use rustc_infer:: traits:: ObligationCause ;
75use rustc_middle:: mir:: interpret:: Scalar ;
86use rustc_middle:: mir:: visit:: NonUseContext :: VarDebugInfo ;
97use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
@@ -18,7 +16,6 @@ use rustc_mir_dataflow::impls::MaybeStorageLive;
1816use rustc_mir_dataflow:: storage:: always_storage_live_locals;
1917use rustc_mir_dataflow:: { Analysis , ResultsCursor } ;
2018use rustc_target:: abi:: { Size , VariantIdx } ;
21- use rustc_trait_selection:: traits:: ObligationCtxt ;
2219
2320#[ derive( Copy , Clone , Debug ) ]
2421enum EdgeKind {
@@ -71,55 +68,6 @@ impl<'tcx> MirPass<'tcx> for Validator {
7168 }
7269}
7370
74- /// Returns whether the two types are equal up to subtyping.
75- ///
76- /// This is used in case we don't know the expected subtyping direction
77- /// and still want to check whether anything is broken.
78- pub fn is_equal_up_to_subtyping < ' tcx > (
79- tcx : TyCtxt < ' tcx > ,
80- param_env : ParamEnv < ' tcx > ,
81- src : Ty < ' tcx > ,
82- dest : Ty < ' tcx > ,
83- ) -> bool {
84- // Fast path.
85- if src == dest {
86- return true ;
87- }
88-
89- // Check for subtyping in either direction.
90- is_subtype ( tcx, param_env, src, dest) || is_subtype ( tcx, param_env, dest, src)
91- }
92-
93- pub fn is_subtype < ' tcx > (
94- tcx : TyCtxt < ' tcx > ,
95- param_env : ParamEnv < ' tcx > ,
96- src : Ty < ' tcx > ,
97- dest : Ty < ' tcx > ,
98- ) -> bool {
99- if src == dest {
100- return true ;
101- }
102-
103- let mut builder =
104- tcx. infer_ctxt ( ) . ignoring_regions ( ) . with_opaque_type_inference ( DefiningAnchor :: Bubble ) ;
105- let infcx = builder. build ( ) ;
106- let ocx = ObligationCtxt :: new ( & infcx) ;
107- let cause = ObligationCause :: dummy ( ) ;
108- let src = ocx. normalize ( cause. clone ( ) , param_env, src) ;
109- let dest = ocx. normalize ( cause. clone ( ) , param_env, dest) ;
110- let Ok ( infer_ok) = infcx. at ( & cause, param_env) . sub ( src, dest) else {
111- return false ;
112- } ;
113- let ( ) = ocx. register_infer_ok_obligations ( infer_ok) ;
114- let errors = ocx. select_all_or_error ( ) ;
115- // With `Reveal::All`, opaque types get normalized away, with `Reveal::UserFacing`
116- // we would get unification errors because we're unable to look into opaque types,
117- // even if they're constrained in our current function.
118- //
119- // It seems very unlikely that this hides any bugs.
120- let _ = infcx. inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ;
121- errors. is_empty ( )
122- }
12371struct TypeChecker < ' a , ' tcx > {
12472 when : & ' a str ,
12573 body : & ' a Body < ' tcx > ,
@@ -195,7 +143,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
195143 return true ;
196144 }
197145
198- is_subtype ( self . tcx , self . param_env , src, dest)
146+ crate :: util :: is_subtype ( self . tcx , self . param_env , src, dest)
199147 }
200148}
201149
0 commit comments