Skip to content

Commit 9039eb8

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 186361 b: refs/heads/try c: a246b65 h: refs/heads/master i: 186359: 6a851c9 v: v3
1 parent 358eca2 commit 9039eb8

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
@@ -2,7 +2,7 @@
22
refs/heads/master: b4c965ee803a4521d8b4575f634e036f93e408f3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
5-
refs/heads/try: d788588dce5525b2bf5674b0c90c791a70582330
5+
refs/heads/try: a246b6542a6660f725441dd016bddd470c761e4c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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/try/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)