@@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata {
450
450
pub fn is_proc_macro_crate ( & self ) -> bool {
451
451
self . root . proc_macro_decls_static . is_some ( )
452
452
}
453
+
453
454
fn is_proc_macro ( & self , id : DefIndex ) -> bool {
454
455
self . is_proc_macro_crate ( ) &&
455
456
self . root . proc_macro_data . unwrap ( ) . decode ( self ) . find ( |x| * x == id) . is_some ( )
456
457
}
457
458
459
+ fn entry_unless_proc_macro ( & self , id : DefIndex ) -> Option < Entry < ' tcx > > {
460
+ match self . is_proc_macro ( id) {
461
+ true => None ,
462
+ false => Some ( self . entry ( id) ) ,
463
+ }
464
+ }
465
+
458
466
fn maybe_entry ( & self , item_id : DefIndex ) -> Option < Lazy < Entry < ' tcx > > > {
459
467
self . root . entries_index . lookup ( self . blob . raw_bytes ( ) , item_id)
460
468
}
@@ -689,10 +697,8 @@ impl<'a, 'tcx> CrateMetadata {
689
697
}
690
698
691
699
pub fn get_deprecation ( & self , id : DefIndex ) -> Option < attr:: Deprecation > {
692
- match self . is_proc_macro ( id) {
693
- true => None ,
694
- false => self . entry ( id) . deprecation . map ( |depr| depr. decode ( self ) ) ,
695
- }
700
+ self . entry_unless_proc_macro ( id)
701
+ . and_then ( |entry| entry. deprecation . map ( |depr| depr. decode ( self ) ) )
696
702
}
697
703
698
704
pub fn get_visibility ( & self , id : DefIndex ) -> ty:: Visibility {
@@ -902,22 +908,24 @@ impl<'a, 'tcx> CrateMetadata {
902
908
self . maybe_entry ( id) . and_then ( |item| item. decode ( self ) . mir ) . is_some ( )
903
909
}
904
910
905
- pub fn maybe_get_optimized_mir ( & self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> Option < Body < ' tcx > > {
906
- match self . is_proc_macro ( id) {
907
- true => None ,
908
- false => self . entry ( id) . mir . map ( |mir| mir. decode ( ( self , tcx) ) ) ,
909
- }
911
+ pub fn get_optimized_mir ( & self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> Body < ' tcx > {
912
+ self . entry_unless_proc_macro ( id)
913
+ . and_then ( |entry| entry. mir . map ( |mir| mir. decode ( ( self , tcx) ) ) )
914
+ . unwrap_or_else ( || {
915
+ bug ! ( "get_optimized_mir: missing MIR for `{:?}" , self . local_def_id( id) )
916
+ } )
910
917
}
911
918
912
- pub fn maybe_get_promoted_mir (
919
+ pub fn get_promoted_mir (
913
920
& self ,
914
921
tcx : TyCtxt < ' tcx > ,
915
922
id : DefIndex ,
916
- ) -> Option < IndexVec < Promoted , Body < ' tcx > > > {
917
- match self . is_proc_macro ( id) {
918
- true => None ,
919
- false => self . entry ( id) . promoted_mir . map ( |promoted| promoted. decode ( ( self , tcx) ) , )
920
- }
923
+ ) -> IndexVec < Promoted , Body < ' tcx > > {
924
+ self . entry_unless_proc_macro ( id)
925
+ . and_then ( |entry| entry. promoted_mir . map ( |promoted| promoted. decode ( ( self , tcx) ) ) )
926
+ . unwrap_or_else ( || {
927
+ bug ! ( "get_promoted_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
928
+ } )
921
929
}
922
930
923
931
pub fn mir_const_qualif ( & self , id : DefIndex ) -> u8 {
0 commit comments