1
1
use rustc_ast:: MetaItem ;
2
2
use rustc_hir:: def_id:: DefId ;
3
3
use rustc_index:: bit_set:: BitSet ;
4
- use rustc_middle:: mir:: { self , Body , Local , Location , MirPass } ;
4
+ use rustc_middle:: mir:: { self , Body , Local , Location } ;
5
5
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
6
6
use rustc_span:: symbol:: { sym, Symbol } ;
7
7
use rustc_span:: Span ;
@@ -18,8 +18,6 @@ use crate::impls::{
18
18
use crate :: move_paths:: { HasMoveData , LookupResult , MoveData , MovePathIndex } ;
19
19
use crate :: { Analysis , JoinSemiLattice , ResultsCursor } ;
20
20
21
- pub struct SanityCheck ;
22
-
23
21
fn has_rustc_mir_with ( tcx : TyCtxt < ' _ > , def_id : DefId , name : Symbol ) -> Option < MetaItem > {
24
22
for attr in tcx. get_attrs ( def_id, sym:: rustc_mir) {
25
23
let items = attr. meta_item_list ( ) ;
@@ -33,53 +31,50 @@ fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option<Me
33
31
None
34
32
}
35
33
36
- // FIXME: This should be a `MirLint`, but it needs to be moved back to `rustc_mir_transform` first.
37
- impl < ' tcx > MirPass < ' tcx > for SanityCheck {
38
- fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
39
- let def_id = body. source . def_id ( ) ;
40
- if !tcx. has_attr ( def_id, sym:: rustc_mir) {
41
- debug ! ( "skipping rustc_peek::SanityCheck on {}" , tcx. def_path_str( def_id) ) ;
42
- return ;
43
- } else {
44
- debug ! ( "running rustc_peek::SanityCheck on {}" , tcx. def_path_str( def_id) ) ;
45
- }
34
+ pub fn sanity_check < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) {
35
+ let def_id = body. source . def_id ( ) ;
36
+ if !tcx. has_attr ( def_id, sym:: rustc_mir) {
37
+ debug ! ( "skipping rustc_peek::SanityCheck on {}" , tcx. def_path_str( def_id) ) ;
38
+ return ;
39
+ } else {
40
+ debug ! ( "running rustc_peek::SanityCheck on {}" , tcx. def_path_str( def_id) ) ;
41
+ }
46
42
47
- let param_env = tcx. param_env ( def_id) ;
48
- let move_data = MoveData :: gather_moves ( body, tcx, param_env, |_| true ) ;
43
+ let param_env = tcx. param_env ( def_id) ;
44
+ let move_data = MoveData :: gather_moves ( body, tcx, param_env, |_| true ) ;
49
45
50
- if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_maybe_init) . is_some ( ) {
51
- let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & move_data)
52
- . into_engine ( tcx, body)
53
- . iterate_to_fixpoint ( ) ;
46
+ if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_maybe_init) . is_some ( ) {
47
+ let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & move_data)
48
+ . into_engine ( tcx, body)
49
+ . iterate_to_fixpoint ( ) ;
54
50
55
- sanity_check_via_rustc_peek ( tcx, flow_inits. into_results_cursor ( body) ) ;
56
- }
51
+ sanity_check_via_rustc_peek ( tcx, flow_inits. into_results_cursor ( body) ) ;
52
+ }
57
53
58
- if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_maybe_uninit) . is_some ( ) {
59
- let flow_uninits = MaybeUninitializedPlaces :: new ( tcx, body, & move_data)
60
- . into_engine ( tcx, body)
61
- . iterate_to_fixpoint ( ) ;
54
+ if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_maybe_uninit) . is_some ( ) {
55
+ let flow_uninits = MaybeUninitializedPlaces :: new ( tcx, body, & move_data)
56
+ . into_engine ( tcx, body)
57
+ . iterate_to_fixpoint ( ) ;
62
58
63
- sanity_check_via_rustc_peek ( tcx, flow_uninits. into_results_cursor ( body) ) ;
64
- }
59
+ sanity_check_via_rustc_peek ( tcx, flow_uninits. into_results_cursor ( body) ) ;
60
+ }
65
61
66
- if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_definite_init) . is_some ( ) {
67
- let flow_def_inits = DefinitelyInitializedPlaces :: new ( body, & move_data)
68
- . into_engine ( tcx, body)
69
- . iterate_to_fixpoint ( ) ;
62
+ if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_definite_init) . is_some ( ) {
63
+ let flow_def_inits = DefinitelyInitializedPlaces :: new ( body, & move_data)
64
+ . into_engine ( tcx, body)
65
+ . iterate_to_fixpoint ( ) ;
70
66
71
- sanity_check_via_rustc_peek ( tcx, flow_def_inits. into_results_cursor ( body) ) ;
72
- }
67
+ sanity_check_via_rustc_peek ( tcx, flow_def_inits. into_results_cursor ( body) ) ;
68
+ }
73
69
74
- if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_liveness) . is_some ( ) {
75
- let flow_liveness = MaybeLiveLocals . into_engine ( tcx, body) . iterate_to_fixpoint ( ) ;
70
+ if has_rustc_mir_with ( tcx, def_id, sym:: rustc_peek_liveness) . is_some ( ) {
71
+ let flow_liveness = MaybeLiveLocals . into_engine ( tcx, body) . iterate_to_fixpoint ( ) ;
76
72
77
- sanity_check_via_rustc_peek ( tcx, flow_liveness. into_results_cursor ( body) ) ;
78
- }
73
+ sanity_check_via_rustc_peek ( tcx, flow_liveness. into_results_cursor ( body) ) ;
74
+ }
79
75
80
- if has_rustc_mir_with ( tcx, def_id, sym:: stop_after_dataflow) . is_some ( ) {
81
- tcx. dcx ( ) . emit_fatal ( StopAfterDataFlowEndedCompilation ) ;
82
- }
76
+ if has_rustc_mir_with ( tcx, def_id, sym:: stop_after_dataflow) . is_some ( ) {
77
+ tcx. dcx ( ) . emit_fatal ( StopAfterDataFlowEndedCompilation ) ;
83
78
}
84
79
}
85
80
0 commit comments