@@ -221,6 +221,7 @@ pub struct State<'a> {
221
221
pub s : pp:: Printer ,
222
222
comments : Option < Comments < ' a > > ,
223
223
ann : & ' a ( dyn PpAnn + ' a ) ,
224
+ is_sdylib_interface : bool ,
224
225
}
225
226
226
227
const INDENT_UNIT : isize = 4 ;
@@ -236,10 +237,37 @@ pub fn print_crate<'a>(
236
237
is_expanded : bool ,
237
238
edition : Edition ,
238
239
g : & AttrIdGenerator ,
240
+ ) -> String {
241
+ let mut s = State {
242
+ s : pp:: Printer :: new ( ) ,
243
+ comments : Some ( Comments :: new ( sm, filename, input) ) ,
244
+ ann,
245
+ is_sdylib_interface : false ,
246
+ } ;
247
+
248
+ print_crate_inner ( & mut s, krate, is_expanded, edition, g) ;
249
+ s. s . eof ( )
250
+ }
251
+
252
+ pub fn print_crate_as_interface (
253
+ krate : & ast:: Crate ,
254
+ edition : Edition ,
255
+ g : & AttrIdGenerator ,
239
256
) -> String {
240
257
let mut s =
241
- State { s : pp:: Printer :: new ( ) , comments : Some ( Comments :: new ( sm , filename , input ) ) , ann } ;
258
+ State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn , is_sdylib_interface : true } ;
242
259
260
+ print_crate_inner ( & mut s, krate, false , edition, g) ;
261
+ s. s . eof ( )
262
+ }
263
+
264
+ fn print_crate_inner < ' a > (
265
+ s : & mut State < ' a > ,
266
+ krate : & ast:: Crate ,
267
+ is_expanded : bool ,
268
+ edition : Edition ,
269
+ g : & AttrIdGenerator ,
270
+ ) {
243
271
// We need to print shebang before anything else
244
272
// otherwise the resulting code will not compile
245
273
// and shebang will be useless.
@@ -282,8 +310,7 @@ pub fn print_crate<'a>(
282
310
s. print_item ( item) ;
283
311
}
284
312
s. print_remaining_comments ( ) ;
285
- s. ann . post ( & mut s, AnnNode :: Crate ( krate) ) ;
286
- s. s . eof ( )
313
+ s. ann . post ( s, AnnNode :: Crate ( krate) ) ;
287
314
}
288
315
289
316
/// Should two consecutive tokens be printed with a space between them?
@@ -1111,7 +1138,7 @@ impl<'a> PrintState<'a> for State<'a> {
1111
1138
1112
1139
impl < ' a > State < ' a > {
1113
1140
pub fn new ( ) -> State < ' a > {
1114
- State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn }
1141
+ State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn , is_sdylib_interface : false }
1115
1142
}
1116
1143
1117
1144
fn commasep_cmnt < T , F , G > ( & mut self , b : Breaks , elts : & [ T ] , mut op : F , mut get_span : G )
0 commit comments