@@ -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,37 @@ 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+ s. s . eof ( )
250+ }
251+
252+ pub fn print_crate_as_interface (
253+ krate : & ast:: Crate ,
254+ edition : Edition ,
255+ g : & AttrIdGenerator ,
239256) -> String {
240257 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 } ;
242259
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+ ) {
243271 // We need to print shebang before anything else
244272 // otherwise the resulting code will not compile
245273 // and shebang will be useless.
@@ -282,8 +310,7 @@ pub fn print_crate<'a>(
282310 s. print_item ( item) ;
283311 }
284312 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) ) ;
287314}
288315
289316/// Should two consecutive tokens be printed with a space between them?
@@ -1111,7 +1138,7 @@ impl<'a> PrintState<'a> for State<'a> {
11111138
11121139impl < ' a > State < ' a > {
11131140 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 }
11151142 }
11161143
11171144 fn commasep_cmnt < T , F , G > ( & mut self , b : Breaks , elts : & [ T ] , mut op : F , mut get_span : G )
0 commit comments