@@ -4,7 +4,6 @@ use crate::dataflow::impls::MaybeStorageLive;
44use crate :: dataflow:: { Analysis , ResultsCursor } ;
55use crate :: util:: storage:: AlwaysLiveLocals ;
66
7- use super :: MirPass ;
87use rustc_middle:: mir:: visit:: { PlaceContext , Visitor } ;
98use rustc_middle:: mir:: {
109 AggregateKind , BasicBlock , Body , BorrowKind , Local , Location , MirPhase , Operand , Rvalue ,
@@ -13,38 +12,32 @@ use rustc_middle::mir::{
1312use rustc_middle:: ty:: relate:: { Relate , RelateResult , TypeRelation } ;
1413use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt } ;
1514
16- #[ derive( Copy , Clone , Debug ) ]
17- enum EdgeKind {
18- Unwind ,
19- Normal ,
15+ pub fn validate_body ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > , when : & str ) {
16+ validate_body_during_phase ( tcx, body, body. phase , when) ;
2017}
2118
22- pub struct Validator {
23- /// Describes at which point in the pipeline this validation is happening.
24- pub when : String ,
25- /// The phase for which we are upholding the dialect. If the given phase forbids a specific
26- /// element, this validator will now emit errors if that specific element is encountered.
27- /// Note that phases that change the dialect cause all *following* phases to check the
28- /// invariants of the new dialect. A phase that changes dialects never checks the new invariants
29- /// itself.
30- pub mir_phase : MirPhase ,
31- }
19+ pub fn validate_body_during_phase (
20+ tcx : TyCtxt < ' tcx > ,
21+ body : & Body < ' tcx > ,
22+ phase : MirPhase ,
23+ when : & str ,
24+ ) {
25+ let def_id = body. source . def_id ( ) ;
26+ let param_env = tcx. param_env ( def_id) ;
3227
33- impl < ' tcx > MirPass < ' tcx > for Validator {
34- fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
35- let def_id = body . source . def_id ( ) ;
36- let param_env = tcx . param_env ( def_id ) ;
37- let mir_phase = self . mir_phase ;
28+ let always_live_locals = AlwaysLiveLocals :: new ( body ) ;
29+ let storage_liveness = MaybeStorageLive :: new ( always_live_locals )
30+ . into_engine ( tcx , body )
31+ . iterate_to_fixpoint ( )
32+ . into_results_cursor ( body ) ;
3833
39- let always_live_locals = AlwaysLiveLocals :: new ( body) ;
40- let storage_liveness = MaybeStorageLive :: new ( always_live_locals)
41- . into_engine ( tcx, body)
42- . iterate_to_fixpoint ( )
43- . into_results_cursor ( body) ;
34+ TypeChecker { when, body, tcx, param_env, mir_phase : phase, storage_liveness } . visit_body ( body) ;
35+ }
4436
45- TypeChecker { when : & self . when , body, tcx, param_env, mir_phase, storage_liveness }
46- . visit_body ( body) ;
47- }
37+ #[ derive( Copy , Clone , Debug ) ]
38+ enum EdgeKind {
39+ Unwind ,
40+ Normal ,
4841}
4942
5043/// Returns whether the two types are equal up to lifetimes.
0 commit comments