@@ -29,6 +29,7 @@ use rustc::mir::Mir;
2929
3030use std:: borrow:: Cow ;
3131use std:: cell:: Ref ;
32+ use std:: collections:: BTreeMap ;
3233use std:: io;
3334use std:: mem;
3435use std:: rc:: Rc ;
@@ -448,16 +449,16 @@ impl<'tcx> EntryKind<'tcx> {
448449}
449450
450451impl < ' a , ' tcx > CrateMetadata {
451- pub fn is_proc_macro ( & self , id : DefIndex ) -> bool {
452+ fn is_proc_macro ( & self , id : DefIndex ) -> bool {
452453 self . proc_macros . is_some ( ) && id != CRATE_DEF_INDEX
453454 }
454455
455- pub fn maybe_entry ( & self , item_id : DefIndex ) -> Option < Lazy < Entry < ' tcx > > > {
456+ fn maybe_entry ( & self , item_id : DefIndex ) -> Option < Lazy < Entry < ' tcx > > > {
456457 assert ! ( !self . is_proc_macro( item_id) ) ;
457458 self . root . index . lookup ( self . blob . raw_bytes ( ) , item_id)
458459 }
459460
460- pub fn entry ( & self , item_id : DefIndex ) -> Entry < ' tcx > {
461+ fn entry ( & self , item_id : DefIndex ) -> Entry < ' tcx > {
461462 match self . maybe_entry ( item_id) {
462463 None => {
463464 bug ! ( "entry: id not found: {:?} in crate {:?} with number {}" ,
@@ -779,6 +780,22 @@ impl<'a, 'tcx> CrateMetadata {
779780 tcx. alloc_tables ( ast. tables . decode ( ( self , tcx) ) )
780781 }
781782
783+ pub fn item_body_nested_bodies ( & self , id : DefIndex ) -> BTreeMap < hir:: BodyId , hir:: Body > {
784+ self . entry ( id) . ast . into_iter ( ) . flat_map ( |ast| {
785+ ast. decode ( self ) . nested_bodies . decode ( self ) . map ( |body| ( body. id ( ) , body) )
786+ } ) . collect ( )
787+ }
788+
789+ pub fn const_is_rvalue_promotable_to_static ( & self , id : DefIndex ) -> bool {
790+ self . entry ( id) . ast . expect ( "const item missing `ast`" )
791+ . decode ( self ) . rvalue_promotable_to_static
792+ }
793+
794+ pub fn is_item_mir_available ( & self , id : DefIndex ) -> bool {
795+ !self . is_proc_macro ( id) &&
796+ self . maybe_entry ( id) . and_then ( |item| item. decode ( self ) . mir ) . is_some ( )
797+ }
798+
782799 pub fn maybe_get_optimized_mir ( & self ,
783800 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
784801 id : DefIndex )
0 commit comments