@@ -15,17 +15,19 @@ use ast;
1515use ast:: { MethodImplItem , RegionTyParamBound , TraitTyParamBound , TraitBoundModifier } ;
1616use ast:: { RequiredMethod , ProvidedMethod , TypeImplItem , TypeTraitItem } ;
1717use ast_util;
18+ use attr;
1819use owned_slice:: OwnedSlice ;
1920use attr:: { AttrMetaMethods , AttributeMethods } ;
2021use codemap:: { self , CodeMap , BytePos } ;
2122use diagnostic;
22- use parse:: token:: { self , BinOpToken , Token } ;
23+ use parse:: token:: { self , BinOpToken , Token , InternedString } ;
2324use parse:: lexer:: comments;
2425use parse;
2526use print:: pp:: { self , break_offset, word, space, zerobreak, hardbreak} ;
2627use print:: pp:: { Breaks , eof} ;
2728use print:: pp:: Breaks :: { Consistent , Inconsistent } ;
2829use ptr:: P ;
30+ use std_inject;
2931
3032use std:: { ascii, mem} ;
3133use std:: old_io:: { self , IoResult } ;
@@ -113,6 +115,25 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
113115 out,
114116 ann,
115117 is_expanded) ;
118+ if is_expanded && std_inject:: use_std ( krate) {
119+ // We need to print `#![no_std]` (and its feature gate) so that
120+ // compiling pretty-printed source won't inject libstd again.
121+ // However we don't want these attributes in the AST because
122+ // of the feature gate, so we fake them up here.
123+
124+ let no_std_meta = attr:: mk_word_item ( InternedString :: new ( "no_std" ) ) ;
125+
126+ // #![feature(no_std)]
127+ let fake_attr = attr:: mk_attr_inner ( attr:: mk_attr_id ( ) ,
128+ attr:: mk_list_item ( InternedString :: new ( "feature" ) ,
129+ vec ! [ no_std_meta. clone( ) ] ) ) ;
130+ try!( s. print_attribute ( & fake_attr) ) ;
131+
132+ // #![no_std]
133+ let fake_attr = attr:: mk_attr_inner ( attr:: mk_attr_id ( ) , no_std_meta) ;
134+ try!( s. print_attribute ( & fake_attr) ) ;
135+ }
136+
116137 try!( s. print_mod ( & krate. module , & krate. attrs [ ] ) ) ;
117138 try!( s. print_remaining_comments ( ) ) ;
118139 eof ( & mut s. s )
0 commit comments