Skip to content

Commit 6919316

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 183275 b: refs/heads/beta c: a246b65 h: refs/heads/master i: 183273: 1c80f92 183271: 149629a v: v3
1 parent 6bd122f commit 6919316

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: d788588dce5525b2bf5674b0c90c791a70582330
34+
refs/heads/beta: a246b6542a6660f725441dd016bddd470c761e4c
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: eb836bf767aa1d8d4cba488a9091cde3c0ab4b2f

branches/beta/src/libsyntax/print/pprust.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ use ast;
1515
use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
1616
use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem};
1717
use ast_util;
18+
use attr;
1819
use owned_slice::OwnedSlice;
1920
use attr::{AttrMetaMethods, AttributeMethods};
2021
use codemap::{self, CodeMap, BytePos};
2122
use diagnostic;
22-
use parse::token::{self, BinOpToken, Token};
23+
use parse::token::{self, BinOpToken, Token, InternedString};
2324
use parse::lexer::comments;
2425
use parse;
2526
use print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
2627
use print::pp::{Breaks, eof};
2728
use print::pp::Breaks::{Consistent, Inconsistent};
2829
use ptr::P;
30+
use std_inject;
2931

3032
use std::{ascii, mem};
3133
use 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)

branches/beta/src/libsyntax/std_inject.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
6969
span: DUMMY_SP
7070
}));
7171

72-
// don't add #![no_std] here, that will block the prelude injection later.
73-
// Add it during the prelude injection instead.
74-
7572
krate
7673
}
7774
}
@@ -87,16 +84,6 @@ struct PreludeInjector<'a>;
8784

8885
impl<'a> fold::Folder for PreludeInjector<'a> {
8986
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
90-
// Add #![no_std] here, so we don't re-inject when compiling pretty-printed source.
91-
// This must happen here and not in StandardLibraryInjector because this
92-
// fold happens second.
93-
94-
let no_std_attr = attr::mk_attr_inner(attr::mk_attr_id(),
95-
attr::mk_word_item(InternedString::new("no_std")));
96-
// std_inject runs after feature checking so manually mark this attr
97-
attr::mark_used(&no_std_attr);
98-
krate.attrs.push(no_std_attr);
99-
10087
// only add `use std::prelude::*;` if there wasn't a
10188
// `#![no_implicit_prelude]` at the crate level.
10289
// fold_mod() will insert glob path.

0 commit comments

Comments
 (0)