@@ -221,6 +221,7 @@ pub struct State<'a> {
221221 pub s : pp:: Printer ,
222222 comments : Option < Comments < ' a > > ,
223223 ann : & ' a ( dyn PpAnn + ' a ) ,
224+ is_sdylib_interface : bool ,
224225}
225226
226227const INDENT_UNIT : isize = 4 ;
@@ -236,10 +237,39 @@ pub fn print_crate<'a>(
236237 is_expanded : bool ,
237238 edition : Edition ,
238239 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 ,
239258) -> String {
240259 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 } ;
242261
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+ ) {
243273 if is_expanded && !krate. attrs . iter ( ) . any ( |attr| attr. has_name ( sym:: no_core) ) {
244274 // We need to print `#![no_std]` (and its feature gate) so that
245275 // compiling pretty-printed source won't inject libstd again.
@@ -277,8 +307,6 @@ pub fn print_crate<'a>(
277307 s. print_item ( item) ;
278308 }
279309 s. print_remaining_comments ( ) ;
280- s. ann . post ( & mut s, AnnNode :: Crate ( krate) ) ;
281- s. s . eof ( )
282310}
283311
284312/// Should two consecutive tokens be printed with a space between them?
@@ -1093,7 +1121,7 @@ impl<'a> PrintState<'a> for State<'a> {
10931121
10941122impl < ' a > State < ' a > {
10951123 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 }
10971125 }
10981126
10991127 fn commasep_cmnt < T , F , G > ( & mut self , b : Breaks , elts : & [ T ] , mut op : F , mut get_span : G )
0 commit comments