@@ -30,6 +30,7 @@ pub struct Ast<'tcx> {
30
30
id_range : IdRange ,
31
31
body : Lazy < hir:: Body > ,
32
32
side_tables : LazySeq < ( ast:: NodeId , TableEntry < ' tcx > ) > ,
33
+ pub nested_bodies : LazySeq < hir:: Body > ,
33
34
pub rvalue_promotable_to_static : bool ,
34
35
}
35
36
@@ -61,13 +62,24 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
61
62
visitor. count
62
63
} ;
63
64
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
+
64
75
let rvalue_promotable_to_static =
65
76
self . tcx . rvalue_promotable_to_static . borrow ( ) [ & body. value . id ] ;
66
77
67
78
self . lazy ( & Ast {
68
79
id_range : id_visitor. result ( ) ,
69
80
body : Lazy :: with_position ( body_pos) ,
70
81
side_tables : LazySeq :: with_position_and_length ( tables_pos, tables_count) ,
82
+ nested_bodies : LazySeq :: with_position_and_length ( nested_pos, nested_count) ,
71
83
rvalue_promotable_to_static : rvalue_promotable_to_static
72
84
} )
73
85
}
@@ -102,6 +114,25 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for SideTableEncodingIdVisitor<'a, 'b, 'tcx> {
102
114
}
103
115
}
104
116
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
+
105
136
/// Decodes an item's body from its AST in the cdata's metadata and adds it to the
106
137
/// ast-map.
107
138
pub fn decode_body < ' a , ' tcx > ( cdata : & CrateMetadata ,
0 commit comments