@@ -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
}
@@ -704,10 +712,8 @@ impl<'a, 'tcx> CrateMetadata {
704
712
}
705
713
706
714
pub fn get_deprecation ( & self , id : DefIndex ) -> Option < attr:: Deprecation > {
707
- match self . is_proc_macro ( id) {
708
- true => None ,
709
- false => self . entry ( id) . deprecation . map ( |depr| depr. decode ( self ) ) ,
710
- }
715
+ self . entry_unless_proc_macro ( id)
716
+ . and_then ( |entry| entry. deprecation . map ( |depr| depr. decode ( self ) ) )
711
717
}
712
718
713
719
pub fn get_visibility ( & self , id : DefIndex ) -> ty:: Visibility {
@@ -918,31 +924,23 @@ impl<'a, 'tcx> CrateMetadata {
918
924
}
919
925
920
926
pub fn get_optimized_mir ( & self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> Body < ' tcx > {
921
- let mir =
922
- match self . is_proc_macro ( id) {
923
- true => None ,
924
- false => self . entry ( id) . mir . map ( |mir| mir. decode ( ( self , tcx) ) ) ,
925
- } ;
926
-
927
- mir. unwrap_or_else ( || {
928
- bug ! ( "get_optimized_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
929
- } )
927
+ self . entry_unless_proc_macro ( id)
928
+ . and_then ( |entry| entry. mir . map ( |mir| mir. decode ( ( self , tcx) ) ) )
929
+ . unwrap_or_else ( || {
930
+ bug ! ( "get_optimized_mir: missing MIR for `{:?}" , self . local_def_id( id) )
931
+ } )
930
932
}
931
933
932
934
pub fn get_promoted_mir (
933
935
& self ,
934
936
tcx : TyCtxt < ' tcx > ,
935
937
id : DefIndex ,
936
938
) -> IndexVec < Promoted , Body < ' tcx > > {
937
- let promoted =
938
- match self . is_proc_macro ( id) {
939
- true => None ,
940
- false => self . entry ( id) . promoted_mir . map ( |promoted| promoted. decode ( ( self , tcx) ) )
941
- } ;
942
-
943
- promoted. unwrap_or_else ( || {
944
- bug ! ( "get_promoted_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
945
- } )
939
+ self . entry_unless_proc_macro ( id)
940
+ . and_then ( |entry| entry. promoted_mir . map ( |promoted| promoted. decode ( ( self , tcx) ) ) )
941
+ . unwrap_or_else ( || {
942
+ bug ! ( "get_promoted_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
943
+ } )
946
944
}
947
945
948
946
pub fn mir_const_qualif ( & self , id : DefIndex ) -> u8 {
0 commit comments