From 5cccf3cd256420d9f32c265e83036dea1d5f94d8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Jul 2015 17:01:14 -0700 Subject: syntax: Implement #![no_core] This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184 --- src/libstd/ffi/os_str.rs | 3 ++- src/libstd/fs.rs | 3 ++- src/libstd/io/cursor.rs | 3 ++- src/libstd/io/impls.rs | 3 ++- src/libstd/io/util.rs | 1 + src/libstd/lib.rs | 10 +++++++--- src/libstd/net/udp.rs | 1 + src/libstd/num/f32.rs | 1 + src/libstd/num/f64.rs | 1 + src/libstd/num/mod.rs | 3 ++- src/libstd/path.rs | 12 ++++++++---- src/libstd/rand/mod.rs | 1 + src/libstd/rand/os.rs | 3 ++- src/libstd/rand/reader.rs | 2 +- src/libstd/rt/args.rs | 6 ++++-- src/libstd/rt/backtrace.rs | 1 + src/libstd/sync/future.rs | 3 ++- src/libstd/sync/mpsc/mod.rs | 1 + src/libstd/sync/mpsc/mpsc_queue.rs | 3 ++- src/libstd/sync/mpsc/oneshot.rs | 3 ++- src/libstd/sync/mpsc/select.rs | 3 ++- src/libstd/sync/mpsc/shared.rs | 3 ++- src/libstd/sync/mpsc/spsc_queue.rs | 3 ++- src/libstd/sync/mpsc/stream.rs | 3 ++- src/libstd/sync/mpsc/sync.rs | 3 ++- src/libstd/sync/once.rs | 1 + src/libstd/sys/common/backtrace.rs | 1 + src/libstd/sys/common/mod.rs | 1 + src/libstd/sys/common/poison.rs | 1 + src/libstd/sys/common/thread_info.rs | 3 ++- src/libstd/sys/common/thread_local.rs | 1 + src/libstd/sys/common/wtf8.rs | 3 ++- src/libstd/sys/unix/backtrace.rs | 1 + src/libstd/sys/unix/condvar.rs | 1 + src/libstd/sys/unix/ext/fs.rs | 1 + src/libstd/sys/unix/ext/process.rs | 1 + src/libstd/sys/unix/fd.rs | 3 ++- src/libstd/sys/unix/fs.rs | 3 ++- src/libstd/sys/unix/mod.rs | 1 + src/libstd/sys/unix/mutex.rs | 1 + src/libstd/sys/unix/os_str.rs | 3 ++- src/libstd/sys/unix/pipe.rs | 1 + src/libstd/sys/unix/rwlock.rs | 1 + src/libstd/sys/unix/stack_overflow.rs | 4 +++- src/libstd/sys/unix/stdio.rs | 1 + src/libstd/sys/unix/thread_local.rs | 1 + src/libstd/sys/windows/backtrace.rs | 1 + src/libstd/sys/windows/condvar.rs | 1 + src/libstd/sys/windows/ext/fs.rs | 1 + src/libstd/sys/windows/fs.rs | 3 ++- src/libstd/sys/windows/handle.rs | 1 + src/libstd/sys/windows/net.rs | 1 + src/libstd/sys/windows/pipe.rs | 1 + src/libstd/sys/windows/rwlock.rs | 1 + src/libstd/sys/windows/stack_overflow.rs | 3 ++- src/libstd/sys/windows/thread.rs | 1 + src/libstd/thread/local.rs | 2 ++ src/libstd/thread/scoped_tls.rs | 3 +++ src/libstd/time/duration.rs | 1 + 59 files changed, 101 insertions(+), 32 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 97bf33335b0..47b8230e430 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -32,7 +32,8 @@ #![unstable(feature = "os_str", reason = "recently added as part of path/io reform")] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use borrow::{Borrow, Cow, ToOwned}; use ffi::CString; diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index a879c2ebd73..62490bb9d08 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -17,7 +17,8 @@ #![stable(feature = "rust1", since = "1.0.0")] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use fmt; use ffi::OsString; diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 980ec51c926..8033d77ff6a 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -292,7 +292,8 @@ impl Write for Cursor> { #[cfg(test)] mod tests { - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use io::prelude::*; use io::{Cursor, SeekFrom}; diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 67bc45d3b62..864870a5905 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use boxed::Box; use cmp; diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 6e651464c74..38e4b0d03e7 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -10,6 +10,7 @@ #![allow(missing_copy_implementations)] +#[cfg(stage0)] use prelude::v1::*; use io::{self, Read, Write, ErrorKind, BufRead}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 2e796004aab..a694a9280dc 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -213,7 +213,6 @@ #![feature(core)] #![feature(core_float)] #![feature(core_intrinsics)] -#![feature(core_prelude)] #![feature(core_simd)] #![feature(drain)] #![feature(fnbox)] @@ -250,6 +249,7 @@ #![cfg_attr(test, feature(float_from_str_radix, range_inclusive, float_extras, hash_default))] #![cfg_attr(test, feature(test, rustc_private, float_consts))] #![cfg_attr(target_env = "msvc", feature(link_args))] +#![cfg_attr(stage0, feature(core, core_prelude))] // Don't link to std. We are std. #![no_std] @@ -257,13 +257,17 @@ #![allow(trivial_casts)] #![deny(missing_docs)] +#[cfg(stage0)] #[macro_use] extern crate core; + #[cfg(test)] extern crate test; #[cfg(test)] #[macro_use] extern crate log; -#[macro_use] +// We want to reexport a few macros from core but libcore has already been +// imported by the compiler (via our #[no_std] attribute) In this case we just +// add a new crate name so we can attach the reexports to it. #[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq, unreachable, unimplemented, write, writeln)] -extern crate core; +extern crate core as __core; #[macro_use] #[macro_reexport(vec, format)] diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 8212b8888d3..290aa6e2fda 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -11,6 +11,7 @@ #![unstable(feature = "udp", reason = "remaining functions have not been \ scrutinized enough to be stabilized")] +#[cfg(stage0)] use prelude::v1::*; use fmt; diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 73d6639cf00..64da75e94db 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -15,6 +15,7 @@ #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] +#[cfg(stage0)] use prelude::v1::*; use core::num; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 3911d276b0f..fcba821522e 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -15,6 +15,7 @@ #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] +#[cfg(stage0)] use prelude::v1::*; use core::num; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 9a52a0214e9..db7fd463e07 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -43,7 +43,8 @@ pub fn test_num(ten: T, two: T) where #[cfg(test)] mod tests { - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use super::*; use i8; use i16; diff --git a/src/libstd/path.rs b/src/libstd/path.rs index f5f8508e9aa..4a4db61c3b9 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -98,7 +98,8 @@ #![stable(feature = "rust1", since = "1.0.0")] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use ascii::*; use borrow::{Borrow, IntoCow, ToOwned, Cow}; @@ -134,7 +135,8 @@ use self::platform::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix}; #[cfg(unix)] mod platform { use super::Prefix; - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use ffi::OsStr; #[inline] @@ -157,7 +159,8 @@ mod platform { #[cfg(windows)] mod platform { - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use ascii::*; use super::{os_str_as_u8_slice, u8_slice_as_os_str, Prefix}; @@ -1747,7 +1750,8 @@ impl AsRef for PathBuf { #[cfg(test)] mod tests { use super::*; - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use string::{ToString, String}; use vec::Vec; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index b806afc5951..df9cd98084b 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -57,6 +57,7 @@ #![unstable(feature = "rand")] +#[cfg(stage0)] use prelude::v1::*; use cell::RefCell; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 3f75c8bca83..9ae9455848e 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -15,7 +15,7 @@ pub use self::imp::OsRng; #[cfg(all(unix, not(target_os = "ios")))] mod imp { - use prelude::v1::*; + #[cfg(stage0)] use prelude::v1::*; use self::OsRngInner::*; use fs::File; @@ -251,6 +251,7 @@ mod imp { #[cfg(windows)] mod imp { + #[cfg(stage0)] use prelude::v1::*; use io; diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index d19bc5b617f..665f423c3f1 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -12,7 +12,7 @@ #![allow(dead_code)] -use prelude::v1::*; +#[cfg(stage0)] use prelude::v1::*; use io::prelude::*; use rand::Rng; diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 52697f00264..e77a2bbd0b9 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -19,7 +19,8 @@ //! //! FIXME #7756: Would be nice for this to not exist. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use vec::Vec; /// One-time global initialization. @@ -140,7 +141,8 @@ mod imp { target_os = "ios", target_os = "windows"))] mod imp { - use core::prelude::*; + #[cfg(stage0)] + use core::prelude::v1::*; use vec::Vec; pub unsafe fn init(_argc: isize, _argv: *const *const u8) { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 2eadf36a6b4..18d93cba8bc 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -12,6 +12,7 @@ #![allow(non_camel_case_types)] +#[cfg(stage0)] use prelude::v1::*; use env; diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index b87a2756829..d0314da19d3 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -39,7 +39,8 @@ outside in crates.io first")] #![allow(deprecated)] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use core::mem::replace; use boxed::Box; diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index d80d858e7a9..954edefcc45 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -265,6 +265,7 @@ // And now that you've seen all the races that I found and attempted to fix, // here's the code for you to find some more! +#[cfg(stage0)] use prelude::v1::*; use sync::Arc; diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index d6d173e5e7e..f45032d327f 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -40,7 +40,8 @@ pub use self::PopResult::*; -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use alloc::boxed::Box; use core::ptr; diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index 7e9c017617d..b84cb3b5472 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -37,7 +37,8 @@ pub use self::UpgradeResult::*; pub use self::SelectionResult::*; use self::MyUpgrade::*; -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use sync::mpsc::Receiver; use sync::mpsc::blocking::{self, SignalToken}; diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index ee1516342ad..1d31ac165f6 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -57,7 +57,8 @@ but no guarantees beyond this are being made")] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use core::cell::{Cell, UnsafeCell}; use core::marker; diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 41c79dd52c8..8c019395d30 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -20,7 +20,8 @@ pub use self::Failure::*; -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use core::cmp; use core::isize; diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 3cf75de5a46..5c0db521007 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -33,7 +33,8 @@ //! concurrently between two threads. This data structure is safe to use and //! enforces the semantics that there is one pusher and one popper. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use alloc::boxed::Box; use core::ptr; diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index 404814b4cd4..a9514da4698 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -22,7 +22,8 @@ pub use self::UpgradeResult::*; pub use self::SelectionResult::*; use self::Message::*; -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use core::cmp; use core::isize; diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 904eab1fd7e..7c9298fff2a 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -33,7 +33,8 @@ /// of a synchronous channel. There are a few branches for the unbuffered case, /// but they're mostly just relevant to blocking senders. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; pub use self::Failure::*; use self::Blocker::*; diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 0bda6a975a2..53191e14bec 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -13,6 +13,7 @@ //! This primitive is meant to be used to run one-time initialization. An //! example use case would be for initializing an FFI library. +#[cfg(stage0)] use prelude::v1::*; use isize; diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index 00932712a07..17953d0af4e 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use io::prelude::*; diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index 69c54f98917..b205b6df4cb 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -10,6 +10,7 @@ #![allow(missing_docs)] +#[cfg(stage0)] use prelude::v1::*; pub mod backtrace; diff --git a/src/libstd/sys/common/poison.rs b/src/libstd/sys/common/poison.rs index 065b1d6c9ac..196fe37d456 100644 --- a/src/libstd/sys/common/poison.rs +++ b/src/libstd/sys/common/poison.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use cell::Cell; diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index bb47c946e49..fb4e0ec70e0 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -10,7 +10,8 @@ #![allow(dead_code)] // stack_guard isn't used right now on all platforms -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use cell::RefCell; use string::String; diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 3b2cb00d8c4..2269a053874 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -58,6 +58,7 @@ #![unstable(feature = "thread_local_internals")] #![allow(dead_code)] // sys isn't exported yet +#[cfg(stage0)] use prelude::v1::*; use sync::atomic::{self, AtomicUsize, Ordering}; diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 3d5d1f5e0eb..0a5f4563dea 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -25,7 +25,8 @@ // unix (it's mostly used on windows), so don't worry about dead code here. #![allow(dead_code)] -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use core::char::{encode_utf8_raw, encode_utf16_raw}; use core::str::next_code_point; diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index ed6421f3670..ae8bfb07aaf 100644 --- a/src/libstd/sys/unix/backtrace.rs +++ b/src/libstd/sys/unix/backtrace.rs @@ -83,6 +83,7 @@ /// to symbols. This is a bit of a hokey implementation as-is, but it works for /// all unix platforms we support right now, so it at least gets the job done. +#[cfg(stage0)] use prelude::v1::*; use io::prelude::*; diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs index beecb445e8d..9dd8df7524d 100644 --- a/src/libstd/sys/unix/condvar.rs +++ b/src/libstd/sys/unix/condvar.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use cell::UnsafeCell; diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 4ee790b0161..dca7f6e829f 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -12,6 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +#[cfg(stage0)] use prelude::v1::*; use fs::{self, Permissions, OpenOptions}; diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index 63adae17581..71f83e7404b 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -14,6 +14,7 @@ use os::unix::raw::{uid_t, gid_t}; use os::unix::io::{FromRawFd, RawFd, AsRawFd, IntoRawFd}; +#[cfg(stage0)] use prelude::v1::*; use process; use sys; diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 026380027d2..bdbe120f79d 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use io; use libc::{self, c_int, size_t, c_void}; diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 0c99a30f107..ddab24b133f 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use io::prelude::*; use os::unix::prelude::*; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 6fd20b940bb..85dc8752443 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -11,6 +11,7 @@ #![allow(missing_docs)] #![allow(non_camel_case_types)] +#[cfg(stage0)] use prelude::v1::*; use io::{self, ErrorKind}; diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs index 6eed403dfc0..a6132b37a66 100644 --- a/src/libstd/sys/unix/mutex.rs +++ b/src/libstd/sys/unix/mutex.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use cell::UnsafeCell; diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index 69d876a48a4..e21d88676e7 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -11,7 +11,8 @@ /// The underlying OsString/OsStr implementation on Unix systems: just /// a `Vec`/`[u8]`. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use borrow::Cow; use fmt::{self, Debug}; diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 140f0c042ba..2abd74bea1b 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use sys::fd::FileDesc; diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs index ee687f350f0..50b4907e6ca 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use libc; diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 62689c39255..ed4e50735a6 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] +use core::prelude::v1::*; + use libc; -use core::prelude::*; use self::imp::{make_handler, drop_handler}; pub use self::imp::{init, cleanup}; diff --git a/src/libstd/sys/unix/stdio.rs b/src/libstd/sys/unix/stdio.rs index fce52f8f92b..8542c660c26 100644 --- a/src/libstd/sys/unix/stdio.rs +++ b/src/libstd/sys/unix/stdio.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use io; diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs index 7238adfcc56..5626446b31c 100644 --- a/src/libstd/sys/unix/thread_local.rs +++ b/src/libstd/sys/unix/thread_local.rs @@ -10,6 +10,7 @@ #![allow(dead_code)] // sys isn't exported yet +#[cfg(stage0)] use prelude::v1::*; use libc::c_int; diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 3f595762fc7..d84513c5f95 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -24,6 +24,7 @@ #![allow(dead_code)] +#[cfg(stage0)] use prelude::v1::*; use io::prelude::*; diff --git a/src/libstd/sys/windows/condvar.rs b/src/libstd/sys/windows/condvar.rs index 04d62200e9b..f3edcfd420c 100644 --- a/src/libstd/sys/windows/condvar.rs +++ b/src/libstd/sys/windows/condvar.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use cell::UnsafeCell; diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index f629e983ce5..e15d1f0ec15 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -12,6 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +#[cfg(stage0)] use prelude::v1::*; use fs::{OpenOptions, Metadata}; diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 4ce6d53cf12..8d81d6576ff 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use io::prelude::*; use os::windows::prelude::*; diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index a566c5eff32..91fe131c251 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use io::ErrorKind; diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index d58355ed1fe..f2aca8d1a6e 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use io; diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index a7ece66e0f1..4044c429d49 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use io; diff --git a/src/libstd/sys/windows/rwlock.rs b/src/libstd/sys/windows/rwlock.rs index 25865286db0..010ffe76fba 100644 --- a/src/libstd/sys/windows/rwlock.rs +++ b/src/libstd/sys/windows/rwlock.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use cell::UnsafeCell; diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index 491b53c4ed9..bc8ee6619f1 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::prelude::*; +#[cfg(stage0)] +use core::prelude::v1::*; use libc::types::os::arch::extra::{LPVOID, DWORD, LONG}; use libc; diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 42805c2ac52..a4131d4cada 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(stage0)] use prelude::v1::*; use alloc::boxed::FnBox; diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 9a6d68acb9f..a6ecd2d88d2 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -12,6 +12,7 @@ #![unstable(feature = "thread_local_internals")] +#[cfg(stage0)] use prelude::v1::*; use cell::UnsafeCell; @@ -271,6 +272,7 @@ impl LocalKey { not(no_elf_tls)))] #[doc(hidden)] mod imp { + #[cfg(stage0)] use prelude::v1::*; use cell::{Cell, UnsafeCell}; diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index cf2c5db8277..1ea33a01791 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -42,6 +42,7 @@ #![unstable(feature = "thread_local_internals")] +#[cfg(stage0)] use prelude::v1::*; #[doc(hidden)] @@ -249,6 +250,7 @@ mod imp { no_elf_tls))] #[doc(hidden)] mod imp { + #[cfg(stage0)] use prelude::v1::*; use cell::Cell; @@ -278,6 +280,7 @@ mod imp { #[cfg(test)] mod tests { use cell::Cell; + #[cfg(stage0)] use prelude::v1::*; scoped_thread_local!(static FOO: u32); diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 8001df29d1f..28eaed40da8 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -12,6 +12,7 @@ #![unstable(feature = "duration", reason = "recently added API per RFC 1040")] +#[cfg(stage0)] use prelude::v1::*; use fmt; -- cgit 1.4.1-3-g733a5 From 0d8340327c03f319b49cb91e2e64aa66dd1e76c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Jul 2015 08:53:22 -0700 Subject: syntax: Don't assume `std` exists for tests This commit removes the injection of `std::env::args()` from `--test` expanded code, relying on the test runner itself to call this funciton. This is more hygienic because we can't assume that `std` exists at the top layer all the time, and it meaks the injected test module entirely self contained. --- src/libstd/lib.rs | 8 -------- src/libstd/process.rs | 2 +- src/libstd/sys/unix/thread.rs | 1 + src/libstd/sys/windows/thread.rs | 2 +- src/libstd/thread/local.rs | 1 + src/libsyntax/test.rs | 23 +++++++++-------------- src/libtest/lib.rs | 19 ++++++++++--------- 7 files changed, 23 insertions(+), 33 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a694a9280dc..7baa7558e52 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -414,11 +414,3 @@ pub mod __rand { // the rustdoc documentation for primitive types. Using `include!` // because rustdoc only looks for these modules at the crate level. include!("primitive_docs.rs"); - -// The expansion of --test has a few references to `::std::$foo` so this module -// is necessary to get things to compile. -#[cfg(test)] -mod std { - pub use option; - pub use realstd::env; -} diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 74a66558627..be921d9aef0 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -815,7 +815,7 @@ mod tests { #[cfg(target_os="android")] #[test] fn test_inherit_env() { - use std::env; + use env; let mut result = env_cmd().output().unwrap(); let output = String::from_utf8(result.stdout).unwrap(); diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 6be61f06926..67ecd4d9229 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -166,6 +166,7 @@ impl Drop for Thread { not(target_os = "netbsd"), not(target_os = "openbsd")))] pub mod guard { + #[cfg(stage0)] use prelude::v1::*; pub unsafe fn current() -> Option { None } diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index a4131d4cada..15df5d756be 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(stage0)] use prelude::v1::*; use alloc::boxed::FnBox; @@ -87,6 +86,7 @@ impl Thread { } pub mod guard { + #[cfg(stage0)] use prelude::v1::*; pub unsafe fn current() -> Option { None } diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index a6ecd2d88d2..0615033736e 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -329,6 +329,7 @@ mod imp { // Due to rust-lang/rust#18804, make sure this is not generic! #[cfg(target_os = "linux")] unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { + use prelude::v1::*; use mem; use libc; use sys_common::thread_local as os; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 2408e6b65a3..ea99291d6c2 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -450,18 +450,11 @@ fn mk_main(cx: &mut TestCtxt) -> P { // test::test_main_static let test_main_path = ecx.path(sp, vec![token::str_to_ident("test"), token::str_to_ident("test_main_static")]); - // ::std::env::args - let os_args_path = ecx.path_global(sp, vec![token::str_to_ident("std"), - token::str_to_ident("env"), - token::str_to_ident("args")]); - // ::std::env::args() - let os_args_path_expr = ecx.expr_path(os_args_path); - let call_os_args = ecx.expr_call(sp, os_args_path_expr, vec![]); // test::test_main_static(...) let test_main_path_expr = ecx.expr_path(test_main_path); let tests_ident_expr = ecx.expr_ident(sp, token::str_to_ident("TESTS")); let call_test_main = ecx.expr_call(sp, test_main_path_expr, - vec![call_os_args, tests_ident_expr]); + vec![tests_ident_expr]); let call_test_main = ecx.stmt_expr(call_test_main); // #![main] let main_meta = ecx.meta_word(sp, token::intern_and_get_ident("main")); @@ -634,12 +627,14 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P { let fail_expr = match test.should_panic { ShouldPanic::No => ecx.expr_path(should_panic_path("No")), ShouldPanic::Yes(ref msg) => { - let path = should_panic_path("Yes"); - let arg = match *msg { - Some(ref msg) => ecx.expr_some(span, ecx.expr_str(span, msg.clone())), - None => ecx.expr_none(span), - }; - ecx.expr_call(span, ecx.expr_path(path), vec![arg]) + match *msg { + Some(ref msg) => { + let msg = ecx.expr_str(span, msg.clone()); + let path = should_panic_path("YesWithMessage"); + ecx.expr_call(span, ecx.expr_path(path), vec![msg]) + } + None => ecx.expr_path(should_panic_path("Yes")), + } } }; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 194b6c8e3e2..7777ea51f82 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -197,7 +197,8 @@ pub struct Bencher { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum ShouldPanic { No, - Yes(Option<&'static str>) + Yes, + YesWithMessage(&'static str) } // The definition of a single test. A test runner will run a list of @@ -262,8 +263,8 @@ pub fn test_main(args: &[String], tests: Vec ) { // a Vec is used in order to effect ownership-transfer // semantics into parallel test runners, which in turn requires a Vec<> // rather than a &[]. -pub fn test_main_static(args: env::Args, tests: &[TestDescAndFn]) { - let args = args.collect::>(); +pub fn test_main_static(tests: &[TestDescAndFn]) { + let args = env::args().collect::>(); let owned_tests = tests.iter().map(|t| { match t.testfn { StaticTestFn(f) => TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() }, @@ -1027,8 +1028,8 @@ pub fn run_test(opts: &TestOpts, fn calc_result(desc: &TestDesc, task_result: Result<(), Box>) -> TestResult { match (&desc.should_panic, task_result) { (&ShouldPanic::No, Ok(())) | - (&ShouldPanic::Yes(None), Err(_)) => TrOk, - (&ShouldPanic::Yes(Some(msg)), Err(ref err)) + (&ShouldPanic::Yes, Err(_)) => TrOk, + (&ShouldPanic::YesWithMessage(msg), Err(ref err)) if err.downcast_ref::() .map(|e| &**e) .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)) @@ -1276,7 +1277,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(None) + should_panic: ShouldPanic::Yes, }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1293,7 +1294,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(Some("error message")) + should_panic: ShouldPanic::YesWithMessage("error message"), }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1310,7 +1311,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(Some("foobar")) + should_panic: ShouldPanic::YesWithMessage("foobar"), }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1327,7 +1328,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(None) + should_panic: ShouldPanic::Yes, }, testfn: DynTestFn(Box::new(move|| f())), }; -- cgit 1.4.1-3-g733a5