@@ -30,6 +30,7 @@ pub struct Ast<'tcx> {
3030 id_range : IdRange ,
3131 body : Lazy < hir:: Body > ,
3232 side_tables : LazySeq < ( ast:: NodeId , TableEntry < ' tcx > ) > ,
33+ pub nested_bodies : LazySeq < hir:: Body > ,
3334 pub rvalue_promotable_to_static : bool ,
3435}
3536
@@ -61,13 +62,24 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
6162 visitor. count
6263 } ;
6364
65+ let nested_pos = self . position ( ) ;
66+ let nested_count = {
67+ let mut visitor = NestedBodyEncodingVisitor {
68+ ecx : self ,
69+ count : 0 ,
70+ } ;
71+ visitor. visit_body ( body) ;
72+ visitor. count
73+ } ;
74+
6475 let rvalue_promotable_to_static =
6576 self . tcx . rvalue_promotable_to_static . borrow ( ) [ & body. value . id ] ;
6677
6778 self . lazy ( & Ast {
6879 id_range : id_visitor. result ( ) ,
6980 body : Lazy :: with_position ( body_pos) ,
7081 side_tables : LazySeq :: with_position_and_length ( tables_pos, tables_count) ,
82+ nested_bodies : LazySeq :: with_position_and_length ( nested_pos, nested_count) ,
7183 rvalue_promotable_to_static : rvalue_promotable_to_static
7284 } )
7385 }
@@ -102,6 +114,25 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for SideTableEncodingIdVisitor<'a, 'b, 'tcx> {
102114 }
103115}
104116
117+ struct NestedBodyEncodingVisitor < ' a , ' b : ' a , ' tcx : ' b > {
118+ ecx : & ' a mut EncodeContext < ' b , ' tcx > ,
119+ count : usize ,
120+ }
121+
122+ impl < ' a , ' b , ' tcx > Visitor < ' tcx > for NestedBodyEncodingVisitor < ' a , ' b , ' tcx > {
123+ fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
124+ NestedVisitorMap :: None
125+ }
126+
127+ fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
128+ let body = self . ecx . tcx . map . body ( body) ;
129+ body. encode ( self . ecx ) . unwrap ( ) ;
130+ self . count += 1 ;
131+
132+ self . visit_body ( body) ;
133+ }
134+ }
135+
105136/// Decodes an item's body from its AST in the cdata's metadata and adds it to the
106137/// ast-map.
107138pub fn decode_body < ' a , ' tcx > ( cdata : & CrateMetadata ,
0 commit comments