11use rustc_ast:: MetaItem ;
22use rustc_hir:: def_id:: DefId ;
33use rustc_index:: bit_set:: BitSet ;
4- use rustc_middle:: mir:: { self , Body , Local , Location , MirPass } ;
4+ use rustc_middle:: mir:: { self , Body , Local , Location } ;
55use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
66use rustc_span:: symbol:: { sym, Symbol } ;
77use rustc_span:: Span ;
@@ -18,8 +18,6 @@ use crate::impls::{
1818use crate :: move_paths:: { HasMoveData , LookupResult , MoveData , MovePathIndex } ;
1919use crate :: { Analysis , JoinSemiLattice , ResultsCursor } ;
2020
21- pub struct SanityCheck ;
22-
2321fn has_rustc_mir_with ( tcx : TyCtxt < ' _ > , def_id : DefId , name : Symbol ) -> Option < MetaItem > {
2422 for attr in tcx. get_attrs ( def_id, sym:: rustc_mir) {
2523 let items = attr. meta_item_list ( ) ;
@@ -33,53 +31,50 @@ fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option<Me
3331 None
3432}
3533
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+ }
4642
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 ) ;
4945
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 ( ) ;
5450
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+ }
5753
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 ( ) ;
6258
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+ }
6561
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 ( ) ;
7066
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+ }
7369
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 ( ) ;
7672
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+ }
7975
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 ) ;
8378 }
8479}
8580
0 commit comments