@@ -3,7 +3,7 @@ use itertools::{Itertools, Position};
33use rustc_ast as ast;
44use rustc_ast:: ModKind ;
55use rustc_ast:: ptr:: P ;
6- use rustc_span:: Ident ;
6+ use rustc_span:: { Ident , Symbol } ;
77
88use crate :: pp:: Breaks :: Inconsistent ;
99use crate :: pprust:: state:: fixup:: FixupContext ;
@@ -148,25 +148,42 @@ impl<'a> State<'a> {
148148 self . end ( ) ; // end outer head-block
149149 }
150150
151+ fn print_extern_crate (
152+ & mut self ,
153+ vis : & ast:: Visibility ,
154+ head : & str ,
155+ ident : Ident ,
156+ orig_name : Option < Symbol > ,
157+ ) {
158+ self . head ( visibility_qualified ( vis, head) ) ;
159+ if let Some ( orig_name) = orig_name {
160+ self . print_name ( orig_name) ;
161+ self . space ( ) ;
162+ self . word ( "as" ) ;
163+ self . space ( ) ;
164+ }
165+ self . print_ident ( ident) ;
166+ self . word ( ";" ) ;
167+ self . end ( ) ; // end inner head-block
168+ self . end ( ) ; // end outer head-block
169+ }
170+
151171 /// Pretty-prints an item.
152172 pub ( crate ) fn print_item ( & mut self , item : & ast:: Item ) {
173+ if self . is_interface && item. span . is_dummy ( ) {
174+ // Do not print prelude for interface files.
175+ return ;
176+ }
153177 self . hardbreak_if_not_bol ( ) ;
154178 self . maybe_print_comment ( item. span . lo ( ) ) ;
155179 self . print_outer_attributes ( & item. attrs ) ;
156180 self . ann . pre ( self , AnnNode :: Item ( item) ) ;
157181 match & item. kind {
158182 ast:: ItemKind :: ExternCrate ( orig_name) => {
159- self . head ( visibility_qualified ( & item. vis , "extern crate" ) ) ;
160- if let & Some ( orig_name) = orig_name {
161- self . print_name ( orig_name) ;
162- self . space ( ) ;
163- self . word ( "as" ) ;
164- self . space ( ) ;
165- }
166- self . print_ident ( item. ident ) ;
167- self . word ( ";" ) ;
168- self . end ( ) ; // end inner head-block
169- self . end ( ) ; // end outer head-block
183+ self . print_extern_crate ( & item. vis , "extern crate" , item. ident , * orig_name) ;
184+ }
185+ ast:: ItemKind :: ExternDynCrate ( orig_name) => {
186+ self . print_extern_crate ( & item. vis , "extern dyn crate" , item. ident , * orig_name) ;
170187 }
171188 ast:: ItemKind :: Use ( tree) => {
172189 self . print_visibility ( & item. vis ) ;
@@ -661,6 +678,12 @@ impl<'a> State<'a> {
661678 self . nbsp ( ) ;
662679 self . print_contract ( contract) ;
663680 }
681+ if self . is_interface {
682+ self . word ( ";" ) ;
683+ self . end ( ) ; // end inner head-block
684+ self . end ( ) ; // end outer head-block
685+ return ;
686+ }
664687 if let Some ( body) = body {
665688 self . nbsp ( ) ;
666689 self . print_block_with_attrs ( body, attrs) ;
0 commit comments