@@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata {
450450 pub fn is_proc_macro_crate ( & self ) -> bool {
451451 self . root . proc_macro_decls_static . is_some ( )
452452 }
453+
453454 fn is_proc_macro ( & self , id : DefIndex ) -> bool {
454455 self . is_proc_macro_crate ( ) &&
455456 self . root . proc_macro_data . unwrap ( ) . decode ( self ) . find ( |x| * x == id) . is_some ( )
456457 }
457458
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+
458466 fn maybe_entry ( & self , item_id : DefIndex ) -> Option < Lazy < Entry < ' tcx > > > {
459467 self . root . entries_index . lookup ( self . blob . raw_bytes ( ) , item_id)
460468 }
@@ -689,10 +697,8 @@ impl<'a, 'tcx> CrateMetadata {
689697 }
690698
691699 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 ) ) )
696702 }
697703
698704 pub fn get_visibility ( & self , id : DefIndex ) -> ty:: Visibility {
@@ -902,22 +908,24 @@ impl<'a, 'tcx> CrateMetadata {
902908 self . maybe_entry ( id) . and_then ( |item| item. decode ( self ) . mir ) . is_some ( )
903909 }
904910
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+ } )
910917 }
911918
912- pub fn maybe_get_promoted_mir (
919+ pub fn get_promoted_mir (
913920 & self ,
914921 tcx : TyCtxt < ' tcx > ,
915922 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+ } )
921929 }
922930
923931 pub fn mir_const_qualif ( & self , id : DefIndex ) -> u8 {
0 commit comments