@@ -15,17 +15,19 @@ use ast;
15
15
use ast:: { MethodImplItem , RegionTyParamBound , TraitTyParamBound , TraitBoundModifier } ;
16
16
use ast:: { RequiredMethod , ProvidedMethod , TypeImplItem , TypeTraitItem } ;
17
17
use ast_util;
18
+ use attr;
18
19
use owned_slice:: OwnedSlice ;
19
20
use attr:: { AttrMetaMethods , AttributeMethods } ;
20
21
use codemap:: { self , CodeMap , BytePos } ;
21
22
use diagnostic;
22
- use parse:: token:: { self , BinOpToken , Token } ;
23
+ use parse:: token:: { self , BinOpToken , Token , InternedString } ;
23
24
use parse:: lexer:: comments;
24
25
use parse;
25
26
use print:: pp:: { self , break_offset, word, space, zerobreak, hardbreak} ;
26
27
use print:: pp:: { Breaks , eof} ;
27
28
use print:: pp:: Breaks :: { Consistent , Inconsistent } ;
28
29
use ptr:: P ;
30
+ use std_inject;
29
31
30
32
use std:: { ascii, mem} ;
31
33
use std:: old_io:: { self , IoResult } ;
@@ -113,6 +115,25 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
113
115
out,
114
116
ann,
115
117
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
+
116
137
try!( s. print_mod ( & krate. module , & krate. attrs [ ] ) ) ;
117
138
try!( s. print_remaining_comments ( ) ) ;
118
139
eof ( & mut s. s )
0 commit comments