@@ -10,19 +10,33 @@ use crate::move_paths::{HasMoveData, MoveData};
10
10
use crate :: move_paths:: { LookupResult , MovePathIndex } ;
11
11
use crate :: MoveDataParamEnv ;
12
12
use crate :: { Analysis , JoinSemiLattice , ResultsCursor } ;
13
+ use rustc_ast:: MetaItem ;
14
+ use rustc_hir:: def_id:: DefId ;
13
15
use rustc_index:: bit_set:: ChunkedBitSet ;
14
16
use rustc_middle:: mir:: MirPass ;
15
17
use rustc_middle:: mir:: { self , Body , Local , Location } ;
16
18
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
17
- use rustc_span:: symbol:: sym;
19
+ use rustc_span:: symbol:: { sym, Symbol } ;
18
20
use rustc_span:: Span ;
19
21
20
22
pub struct SanityCheck ;
21
23
24
+ pub fn has_rustc_mir_with ( tcx : TyCtxt < ' _ > , def_id : DefId , name : Symbol ) -> Option < MetaItem > {
25
+ for attr in tcx. get_attrs ( def_id, sym:: rustc_mir) {
26
+ let items = attr. meta_item_list ( ) ;
27
+ for item in items. iter ( ) . flat_map ( |l| l. iter ( ) ) {
28
+ match item. meta_item ( ) {
29
+ Some ( mi) if mi. has_name ( name) => return Some ( mi. clone ( ) ) ,
30
+ _ => continue ,
31
+ }
32
+ }
33
+ }
34
+ None
35
+ }
36
+
22
37
// FIXME: This should be a `MirLint`, but it needs to be moved back to `rustc_mir_transform` first.
23
38
impl < ' tcx > MirPass < ' tcx > for SanityCheck {
24
39
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
25
- use crate :: has_rustc_mir_with;
26
40
let def_id = body. source . def_id ( ) ;
27
41
if !tcx. has_attr ( def_id, sym:: rustc_mir) {
28
42
debug ! ( "skipping rustc_peek::SanityCheck on {}" , tcx. def_path_str( def_id) ) ;
0 commit comments