Skip to content

Commit

Permalink
syntax: Implement #![no_core]
Browse files Browse the repository at this point in the history
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]: rust-lang/rfcs#1184
  • Loading branch information
alexcrichton committed Aug 4, 2015
1 parent ceded6a commit 5cccf3c
Show file tree
Hide file tree
Showing 157 changed files with 478 additions and 385 deletions.
3 changes: 2 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@

use boxed::Box;

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::atomic;
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use heap;
use raw_vec::RawVec;
Expand Down
7 changes: 3 additions & 4 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#![feature(coerce_unsized)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(core_prelude)]
#![feature(core_slice_ext)]
#![feature(custom_attribute)]
#![feature(fundamental)]
Expand All @@ -93,17 +92,17 @@
#![feature(unsize)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![cfg_attr(stage0, feature(core, core_prelude))]

#![cfg_attr(test, feature(test, alloc, rustc_private, box_raw))]
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
feature(libc))]

#[macro_use]
extern crate core;

#[cfg(all(not(feature = "external_funcs"), not(feature = "external_crate")))]
extern crate libc;

#[cfg(stage0)] #[macro_use] extern crate core;

// Allow testing this library

#[cfg(test)] #[macro_use] extern crate std;
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

#[cfg(not(test))]
use boxed::Box;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
#![allow(missing_docs)]
#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::iter::{FromIterator};
use core::mem::swap;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
//! println!("There are {} primes below {}", num_primes, max_prime);
//! ```

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::Ordering;
use core::cmp;
Expand Down
6 changes: 4 additions & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

use self::Entry::*;

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::Ordering;
use core::fmt::Debug;
Expand Down Expand Up @@ -530,7 +531,8 @@ enum Continuation<A, B> {
/// to nodes. By using this module much better safety guarantees can be made, and more search
/// boilerplate gets cut out.
mod stack {
use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;
use core::marker;
use core::mem;
use core::ops::{Deref, DerefMut};
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub use self::SearchResult::*;
pub use self::ForceResult::*;
pub use self::TraversalItem::*;

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::Ordering::{Greater, Less, Equal};
use core::intrinsics::arith_offset;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// This is pretty much entirely stolen from TreeSet, since BTreeMap has an identical interface
// to TreeMap

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::Ordering::{self, Less, Greater, Equal};
use core::fmt::Debug;
Expand Down
4 changes: 3 additions & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
reason = "matches collection reform specification, \
waiting for dust to settle")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::marker;
use core::fmt;
use core::iter::{FromIterator};
Expand Down
6 changes: 2 additions & 4 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
#![feature(alloc)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(core_prelude)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![feature(heap_api)]
Expand All @@ -62,12 +60,12 @@
#![feature(utf8_error)]
#![cfg_attr(test, feature(rand, test))]
#![cfg_attr(not(test), feature(str_words))]
#![cfg_attr(stage0, feature(core, core_prelude))]

#![feature(no_std)]
#![no_std]

#[macro_use]
extern crate core;
#[cfg(stage0)] #[macro_use] extern crate core;

extern crate rustc_unicode;
extern crate alloc;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use alloc::boxed::Box;
use core::cmp::Ordering;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::fmt;
use core::hash;
Expand Down
4 changes: 3 additions & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use alloc::raw_vec::RawVec;
use alloc::boxed::Box;
use alloc::heap::EMPTY;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::Ordering;
use core::fmt;
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

use self::Entry::*;

use core::prelude::*;
#[cfg(stage0)]
use core::prelude::v1::*;

use core::cmp::{max, Ordering};
use core::fmt;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use prelude::*;
use prelude::v1::*;
use fmt::{self, Write, FlagV1};

struct PadAdapter<'a, 'b: 'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;
use prelude::v1::*;

use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
use marker::PhantomData;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// FIXME: #6220 Implement floating point formatting

use prelude::*;
use prelude::v1::*;

use fmt;
use num::Zero;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;
use prelude::v1::*;

use mem;

Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn hash<T: Hash, H: Hasher + Default>(value: &T) -> u64 {
//////////////////////////////////////////////////////////////////////////////

mod impls {
use prelude::*;
use prelude::v1::*;

use slice;
use super::*;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

//! An implementation of SipHash 2-4.

use prelude::v1::*;

use ptr;
use prelude::*;
use super::Hasher;

/// An implementation of SipHash 2-4.
Expand Down
7 changes: 5 additions & 2 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
html_playground_url = "http://play.rust-lang.org/")]
#![doc(test(no_crate_inject))]

#![feature(no_std)]
#![no_std]
#![cfg_attr(stage0, feature(no_std))]
#![cfg_attr(stage0, no_std)]
#![cfg_attr(not(stage0), feature(no_core))]
#![cfg_attr(not(stage0), no_core)]
#![allow(raw_pointer_derive)]
#![deny(missing_docs)]

Expand Down Expand Up @@ -168,6 +170,7 @@ mod tuple;
// compiling the core library when it's compiling this library, so it expands
// all references to `::core::$foo`
#[doc(hidden)]
#[cfg(stage0)]
mod core {
pub use intrinsics; // derive(PartialOrd)
pub use fmt; // format_args!
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;
use prelude::v1::*;

use intrinsics;
use mem;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;
use prelude::v1::*;

use intrinsics;
use mem;
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/num/flt2dec/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

#![macro_use]

use prelude::*;
use prelude::v1::*;

use mem;
use intrinsics;

Expand Down Expand Up @@ -351,7 +352,7 @@ define_bignum!(Big32x36: type=Digit32, n=36);
// this one is used for testing only.
#[doc(hidden)]
pub mod tests {
use prelude::*;
use prelude::v1::*;
define_bignum!(Big8x3: type=u8, n=3);
}

2 changes: 1 addition & 1 deletion src/libcore/num/flt2dec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! Decodes a floating-point value into individual parts and error ranges.

use prelude::*;
use prelude::v1::*;

use {f32, f64};
use num::{Float, FpCategory};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ functions.
#![unstable(feature = "flt2dec",
reason = "internal routines only exposed for testing")]

use prelude::*;
use prelude::v1::*;
use i16;
use num::Float;
use slice::bytes;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Almost direct (but slightly optimized) Rust translation of Figure 3 of [1].
quickly and accurately. SIGPLAN Not. 31, 5 (May. 1996), 108-116.
*/

use prelude::*;
use prelude::v1::*;

use num::Float;
use cmp::Ordering;

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Rust adaptation of Grisu3 algorithm described in [1]. It uses about
accurately with integers. SIGPLAN Not. 45, 6 (June 2010), 233-243.
*/

use prelude::*;
use prelude::v1::*;

use num::Float;

use num::flt2dec::{Decoded, MAX_SIG_DIGITS, round_up};
Expand Down
13 changes: 13 additions & 0 deletions src/libcore/prelude/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The libcore prelude

pub mod v1;
14 changes: 2 additions & 12 deletions src/libcore/prelude.rs → src/libcore/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@
//! The core prelude
//!
//! This module is intended for users of libcore which do not link to libstd as
//! well. This module is not imported by default, but using the entire contents
//! of this module will provide all of the useful traits and types in libcore
//! that one would expect from the standard library as well.
//!
//! There is no method to automatically inject this prelude, and this prelude is
//! a subset of the standard library's prelude.
//!
//! # Example
//!
//! ```ignore
//! use core::prelude::*;
//! ```
//! well. This module is imported by default when `#![no_std]` is used in the
//! same manner as the standard library's prelude.

#![unstable(feature = "core_prelude",
reason = "the libcore prelude has not been scrutinized and \
Expand Down
Loading

0 comments on commit 5cccf3c

Please sign in to comment.