2
2
3
3
use rustc_data_structures:: fx:: FxHashSet ;
4
4
use rustc_index:: bit_set:: BitSet ;
5
- use rustc_infer:: infer:: { DefiningAnchor , TyCtxtInferExt } ;
6
- use rustc_infer:: traits:: ObligationCause ;
7
5
use rustc_middle:: mir:: interpret:: Scalar ;
8
6
use rustc_middle:: mir:: visit:: NonUseContext :: VarDebugInfo ;
9
7
use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
@@ -18,7 +16,6 @@ use rustc_mir_dataflow::impls::MaybeStorageLive;
18
16
use rustc_mir_dataflow:: storage:: always_storage_live_locals;
19
17
use rustc_mir_dataflow:: { Analysis , ResultsCursor } ;
20
18
use rustc_target:: abi:: { Size , VariantIdx } ;
21
- use rustc_trait_selection:: traits:: ObligationCtxt ;
22
19
23
20
#[ derive( Copy , Clone , Debug ) ]
24
21
enum EdgeKind {
@@ -71,55 +68,6 @@ impl<'tcx> MirPass<'tcx> for Validator {
71
68
}
72
69
}
73
70
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
- }
123
71
struct TypeChecker < ' a , ' tcx > {
124
72
when : & ' a str ,
125
73
body : & ' a Body < ' tcx > ,
@@ -195,7 +143,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
195
143
return true ;
196
144
}
197
145
198
- is_subtype ( self . tcx , self . param_env , src, dest)
146
+ crate :: util :: is_subtype ( self . tcx , self . param_env , src, dest)
199
147
}
200
148
}
201
149
0 commit comments