Skip to content

Commit 3372046

Browse files
author
Keegan McAllister
committed
Don't use std:: paths in syntax extensions when compiling a #![no_std] crate
Fixes #16803.
1 parent b6f76b9 commit 3372046

39 files changed

+229
-112
lines changed

src/liballoc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ fn oom() -> ! {
124124
#[doc(hidden)]
125125
pub fn fixme_14344_be_sure_to_link_to_collections() {}
126126

127-
#[cfg(not(test))]
127+
// NOTE: Remove after next snapshot
128+
#[cfg(stage0, not(test))]
128129
#[doc(hidden)]
129130
mod std {
130131
pub use core::fmt;

src/libcollections/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ use core::iter::{Chain, Enumerate, Repeat, Skip, Take};
7070
use core::iter;
7171
use core::slice;
7272
use core::uint;
73-
use std::hash;
7473

7574
use {Mutable, Set, MutableSet, MutableSeq};
7675
use vec::Vec;
76+
use hash;
7777

7878
type MatchWords<'a> = Chain<MaskWords<'a>, Skip<Take<Enumerate<Repeat<uint>>>>>;
7979
// Take two BitV's, and return iterators of their words, where the shorter one

src/libcollections/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use core::fmt;
2929
use core::iter;
3030
use core::mem;
3131
use core::ptr;
32-
use std::hash::{Writer, Hash};
3332

3433
use {Mutable, Deque, MutableSeq};
34+
use hash::{Writer, Hash};
3535

3636
/// A doubly-linked list.
3737
pub struct DList<T> {
@@ -742,13 +742,13 @@ impl<S: Writer, A: Hash<S>> Hash<S> for DList<A> {
742742
mod tests {
743743
use std::prelude::*;
744744
use std::rand;
745-
use std::hash;
746745
use test::Bencher;
747746
use test;
748747

749748
use {Deque, MutableSeq};
750749
use super::{DList, Node, ListInsertion};
751750
use vec::Vec;
751+
use hash;
752752

753753
pub fn check_links<T>(list: &DList<T>) {
754754
let mut len = 0u;

src/libcollections/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,20 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}
558558

559559
#[cfg(not(test))]
560560
mod std {
561+
// NOTE: Remove after next snapshot
562+
#[cfg(stage0)] pub use core::option; // necessary for fail!()
563+
#[cfg(stage0)] pub use core::clone; // deriving(Clone)
564+
#[cfg(stage0)] pub use core::cmp; // deriving(Eq, Ord, etc.)
565+
#[cfg(stage0)] pub use hash; // deriving(Hash)
566+
561567
pub use core::fmt; // necessary for fail!()
562-
pub use core::option; // necessary for fail!()
563-
pub use core::clone; // deriving(Clone)
564-
pub use core::cmp; // deriving(Eq, Ord, etc.)
565-
pub use hash; // deriving(Hash)
566568

569+
#[cfg(stage0)]
567570
pub mod collections {
568571
pub use MutableSeq;
569572
}
570573
}
574+
575+
mod collections {
576+
pub use hash; // deriving(Hsah)
577+
}

src/libcollections/ringbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use core::cmp;
1919
use core::default::Default;
2020
use core::fmt;
2121
use core::iter;
22-
use std::hash::{Writer, Hash};
2322

2423
use {Deque, Mutable, MutableSeq};
2524
use vec::Vec;
25+
use hash::{Writer, Hash};
2626

2727
static INITIAL_CAPACITY: uint = 8u; // 2^3
2828
static MINIMUM_CAPACITY: uint = 2u;
@@ -527,13 +527,13 @@ mod tests {
527527
use std::fmt::Show;
528528
use std::prelude::*;
529529
use std::gc::{GC, Gc};
530-
use std::hash;
531530
use test::Bencher;
532531
use test;
533532

534533
use {Deque, Mutable, MutableSeq};
535534
use super::RingBuf;
536535
use vec::Vec;
536+
use hash;
537537

538538
#[test]
539539
fn test_simple() {

src/libcollections/treemap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ use core::iter::Peekable;
3838
use core::iter;
3939
use core::mem::{replace, swap};
4040
use core::ptr;
41-
use std::hash::{Writer, Hash};
4241

4342
use {Mutable, Set, MutableSet, MutableMap, Map, MutableSeq};
4443
use vec::Vec;
44+
use hash::{Writer, Hash};
4545

4646
/// This is implemented as an AA tree, which is a simplified variation of
4747
/// a red-black tree where red (horizontal) nodes can only be added
@@ -2248,10 +2248,10 @@ mod bench {
22482248
#[cfg(test)]
22492249
mod test_set {
22502250
use std::prelude::*;
2251-
use std::hash;
22522251

22532252
use {Set, MutableSet, Mutable, MutableMap, MutableSeq};
22542253
use super::{TreeMap, TreeSet};
2254+
use hash;
22552255

22562256
#[test]
22572257
fn test_clear() {

src/libcollections/trie.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use core::mem::zeroed;
2121
use core::mem;
2222
use core::uint;
2323
use core::iter;
24-
use std::hash::{Writer, Hash};
2524

2625
use {Mutable, Map, MutableMap, Set, MutableSet};
2726
use slice::{Items, MutItems};
2827
use slice;
28+
use hash::{Writer, Hash};
2929

3030
// FIXME: #5244: need to manually update the TrieNode constructor
3131
static SHIFT: uint = 4;
@@ -1019,10 +1019,10 @@ mod test_map {
10191019
use std::prelude::*;
10201020
use std::iter::range_step;
10211021
use std::uint;
1022-
use std::hash;
10231022

10241023
use {MutableMap, Map, MutableSeq};
10251024
use super::{TrieMap, TrieNode, Internal, External, Nothing};
1025+
use hash;
10261026

10271027
fn check_integrity<T>(trie: &TrieNode<T>) {
10281028
assert!(trie.count != 0);

src/libcore/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![stable]
1414

1515
use intrinsics;
16-
use std::kinds::marker;
16+
use kinds::marker;
1717
use cell::UnsafeCell;
1818

1919
/// An atomic boolean type.

src/libcore/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ pub mod unit;
134134
pub mod fmt;
135135

136136
#[doc(hidden)]
137-
mod core {
138-
pub use failure;
137+
mod std {
138+
// NOTE: Remove after next snapshot
139+
#[cfg(stage0)] pub use clone;
140+
#[cfg(stage0)] pub use cmp;
141+
#[cfg(stage0)] pub use kinds;
142+
#[cfg(stage0)] pub use option;
143+
144+
pub use fmt;
139145
}
140146

141147
#[doc(hidden)]
142-
mod std {
148+
mod core {
149+
pub use failure;
143150
pub use clone;
144151
pub use cmp;
145152
pub use kinds;

src/libcore/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278

279279
use clone::Clone;
280280
use cmp::PartialEq;
281-
use std::fmt::Show;
281+
use fmt::Show;
282282
use slice;
283283
use slice::Slice;
284284
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};

src/librustc/driver/driver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
273273
let cfg = syntax::ext::expand::ExpansionConfig {
274274
deriving_hash_type_parameter: sess.features.default_type_params.get(),
275275
crate_name: crate_name.to_string(),
276+
use_std: front::std_inject::use_std(&krate),
276277
};
277278
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
278279
cfg,

src/librustc/front/std_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn maybe_inject_prelude(sess: &Session, krate: ast::Crate) -> ast::Crate {
4343
}
4444
}
4545

46-
fn use_std(krate: &ast::Crate) -> bool {
46+
pub fn use_std(krate: &ast::Crate) -> bool {
4747
!attr::contains_name(krate.attrs.as_slice(), "no_std")
4848
}
4949

src/librustc/front/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![allow(unused_imports)]
1515

1616
use driver::session::Session;
17-
use front::config;
17+
use front::{config, std_inject};
1818

1919
use std::slice;
2020
use std::mem;
@@ -232,6 +232,7 @@ fn generate_test_harness(sess: &Session,
232232
ExpansionConfig {
233233
deriving_hash_type_parameter: false,
234234
crate_name: "test".to_string(),
235+
use_std: std_inject::use_std(&krate),
235236
}),
236237
path: Vec::new(),
237238
testfns: Vec::new(),

src/librustrt/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,8 @@ pub mod shouldnt_be_public {
166166

167167
#[cfg(not(test))]
168168
mod std {
169-
pub use core::{fmt, option, cmp};
169+
// NOTE: Remove after next snapshot
170+
#[cfg(stage0)] pub use core::{option, cmp};
171+
172+
pub use core::fmt;
170173
}

src/libstd/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,13 @@ mod failure;
273273
#[doc(hidden)]
274274
mod std {
275275
// mods used for deriving
276-
pub use clone;
277-
pub use cmp;
278-
pub use hash;
276+
// NOTE: Remove after next snapshot
277+
#[cfg(stage0)] pub use clone;
278+
#[cfg(stage0)] pub use cmp;
279+
#[cfg(stage0)] pub use hash;
279280

280281
pub use comm; // used for select!()
281-
pub use fmt; // used for any formatting strings
282+
pub use fmt; // used for fail!()
282283
pub use io; // used for println!()
283284
pub use local_data; // used for local_data_key!()
284285
pub use option; // used for bitflags!{}

src/libstd/num/strconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use num;
2121
use ops::{Add, Sub, Mul, Div, Rem, Neg};
2222
use option::{None, Option, Some};
2323
use slice::{ImmutableSlice, MutableSlice};
24-
use std::cmp::{PartialOrd, PartialEq};
24+
use cmp::{PartialOrd, PartialEq};
2525
use str::StrSlice;
2626
use string::String;
2727
use vec::Vec;

src/libsync/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,8 @@ mod lock;
7676

7777
#[cfg(not(test))]
7878
mod std {
79-
pub use core::{fmt, option, cmp, clone};
79+
// NOTE: Remove after next snapshot
80+
#[cfg(stage0)] pub use core::{option, cmp, clone};
81+
82+
pub use core::fmt; // for fail!()
8083
}

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ impl<'a> ExtCtxt<'a> {
588588
pub fn ident_of(&self, st: &str) -> ast::Ident {
589589
str_to_ident(st)
590590
}
591+
pub fn ident_of_std(&self, st: &str) -> ast::Ident {
592+
self.ident_of(if self.ecfg.use_std { "std" } else { st })
593+
}
591594
pub fn name_of(&self, st: &str) -> ast::Name {
592595
token::intern(st)
593596
}

0 commit comments

Comments
 (0)