@@ -29,6 +29,7 @@ use rustc::mir::Mir;
29
29
30
30
use std:: borrow:: Cow ;
31
31
use std:: cell:: Ref ;
32
+ use std:: collections:: BTreeMap ;
32
33
use std:: io;
33
34
use std:: mem;
34
35
use std:: rc:: Rc ;
@@ -448,16 +449,16 @@ impl<'tcx> EntryKind<'tcx> {
448
449
}
449
450
450
451
impl < ' a , ' tcx > CrateMetadata {
451
- pub fn is_proc_macro ( & self , id : DefIndex ) -> bool {
452
+ fn is_proc_macro ( & self , id : DefIndex ) -> bool {
452
453
self . proc_macros . is_some ( ) && id != CRATE_DEF_INDEX
453
454
}
454
455
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 > > > {
456
457
assert ! ( !self . is_proc_macro( item_id) ) ;
457
458
self . root . index . lookup ( self . blob . raw_bytes ( ) , item_id)
458
459
}
459
460
460
- pub fn entry ( & self , item_id : DefIndex ) -> Entry < ' tcx > {
461
+ fn entry ( & self , item_id : DefIndex ) -> Entry < ' tcx > {
461
462
match self . maybe_entry ( item_id) {
462
463
None => {
463
464
bug ! ( "entry: id not found: {:?} in crate {:?} with number {}" ,
@@ -779,6 +780,22 @@ impl<'a, 'tcx> CrateMetadata {
779
780
tcx. alloc_tables ( ast. tables . decode ( ( self , tcx) ) )
780
781
}
781
782
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
+
782
799
pub fn maybe_get_optimized_mir ( & self ,
783
800
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
784
801
id : DefIndex )
0 commit comments