@@ -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,39 @@ 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
+
250
+ s. ann . post ( & mut s, AnnNode :: Crate ( krate) ) ;
251
+ s. s . eof ( )
252
+ }
253
+
254
+ pub fn print_crate_as_interface (
255
+ krate : & ast:: Crate ,
256
+ edition : Edition ,
257
+ g : & AttrIdGenerator ,
239
258
) -> String {
240
259
let mut s =
241
- State { s : pp:: Printer :: new ( ) , comments : Some ( Comments :: new ( sm , filename , input ) ) , ann } ;
260
+ State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn , is_sdylib_interface : true } ;
242
261
262
+ print_crate_inner ( & mut s, krate, false , edition, g) ;
263
+ s. s . eof ( )
264
+ }
265
+
266
+ fn print_crate_inner < ' a > (
267
+ s : & mut State < ' a > ,
268
+ krate : & ast:: Crate ,
269
+ is_expanded : bool ,
270
+ edition : Edition ,
271
+ g : & AttrIdGenerator ,
272
+ ) {
243
273
if is_expanded && !krate. attrs . iter ( ) . any ( |attr| attr. has_name ( sym:: no_core) ) {
244
274
// We need to print `#![no_std]` (and its feature gate) so that
245
275
// compiling pretty-printed source won't inject libstd again.
@@ -277,8 +307,6 @@ pub fn print_crate<'a>(
277
307
s. print_item ( item) ;
278
308
}
279
309
s. print_remaining_comments ( ) ;
280
- s. ann . post ( & mut s, AnnNode :: Crate ( krate) ) ;
281
- s. s . eof ( )
282
310
}
283
311
284
312
/// Should two consecutive tokens be printed with a space between them?
@@ -1093,7 +1121,7 @@ impl<'a> PrintState<'a> for State<'a> {
1093
1121
1094
1122
impl < ' a > State < ' a > {
1095
1123
pub fn new ( ) -> State < ' a > {
1096
- State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn }
1124
+ State { s : pp:: Printer :: new ( ) , comments : None , ann : & NoAnn , is_sdylib_interface : false }
1097
1125
}
1098
1126
1099
1127
fn commasep_cmnt < T , F , G > ( & mut self , b : Breaks , elts : & [ T ] , mut op : F , mut get_span : G )
0 commit comments