Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-gate #![no_std] and fix most syntax extensions #21988

Merged
merged 6 commits into from
Feb 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,12 @@ The currently implemented features of the reference compiler are:

* `associated_types` - Allows type aliases in traits. Experimental.

* `no_std` - Allows the `#![no_std]` crate attribute, which disables the implicit
`extern crate std`. This typically requires use of the unstable APIs
behind the libstd "facade", such as libcore and libcollections. It
may also cause problems when using syntax extensions, including
`#[derive]`.

If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about #[feature] directives which enabled
the new feature (because the directive is no longer necessary). However, if a
Expand Down
12 changes: 5 additions & 7 deletions src/doc/trpl/unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ attribute attached to the crate.
```ignore
// a minimal library
#![crate_type="lib"]
#![feature(no_std)]
#![no_std]
# // fn main() {} tricked you, rustdoc!
```
Expand All @@ -446,8 +447,8 @@ The function marked `#[start]` is passed the command line parameters
in the same format as C:

```
#![feature(lang_items, start, no_std)]
#![no_std]
#![feature(lang_items, start)]

// Pull in the system libc library for what crt0.o likely requires
extern crate libc;
Expand All @@ -473,6 +474,7 @@ correct ABI and the correct name, which requires overriding the
compiler's name mangling too:

```ignore
#![feature(no_std)]
#![no_std]
#![no_main]
#![feature(lang_items, start)]
Expand Down Expand Up @@ -528,8 +530,8 @@ As an example, here is a program that will calculate the dot product of two
vectors provided from C, using idiomatic Rust practices.

```
#![feature(lang_items, start, no_std)]
#![no_std]
#![feature(lang_items, start)]

# extern crate libc;
extern crate core;
Expand Down Expand Up @@ -576,10 +578,6 @@ extern fn panic_fmt(args: &core::fmt::Arguments,
#[lang = "eh_personality"] extern fn eh_personality() {}
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }
# fn main() {}
# mod std { // for-loops
# pub use core::iter;
# pub use core::option;
# }
```

Note that there is one extra lang item here which differs from the examples
Expand Down Expand Up @@ -656,8 +654,8 @@ and one for deallocation. A freestanding program that uses the `Box`
sugar for dynamic allocations via `malloc` and `free`:

```
#![feature(lang_items, box_syntax, start, no_std)]
#![no_std]
#![feature(lang_items, box_syntax, start)]

extern crate libc;

Expand Down
4 changes: 3 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![feature(no_std)]
#![no_std]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]
Expand Down Expand Up @@ -126,7 +127,8 @@ pub fn oom() -> ! {
#[doc(hidden)]
pub fn fixme_14344_be_sure_to_link_to_collections() {}

#[cfg(not(test))]
// NOTE: remove after next snapshot
#[cfg(all(stage0, not(test)))]
#[doc(hidden)]
mod std {
pub use core::fmt;
Expand Down
22 changes: 17 additions & 5 deletions src/libstd/fmt.rs → src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -134,7 +134,7 @@
//! * `E` ⇒ `UpperExp`
//!
//! What this means is that any type of argument which implements the
//! `std::fmt::Binary` trait can then be formatted with `{:b}`. Implementations
//! `fmt::Binary` trait can then be formatted with `{:b}`. Implementations
//! are provided for these traits for a number of primitive types by the
//! standard library as well. If no format is specified (as in `{}` or `{:6}`),
//! then the format trait used is the `Display` trait.
Expand All @@ -146,7 +146,7 @@
//! # use std::fmt;
//! # struct Foo; // our custom type
//! # impl fmt::Display for Foo {
//! fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//! # write!(f, "testing, testing")
//! # } }
//! ```
Expand Down Expand Up @@ -403,8 +403,6 @@

#![unstable(feature = "std_misc")]

use string;

pub use core::fmt::{Formatter, Result, Writer, rt};
pub use core::fmt::{Show, String, Octal, Binary};
pub use core::fmt::{Display, Debug};
Expand All @@ -413,6 +411,8 @@ pub use core::fmt::{LowerExp, UpperExp};
pub use core::fmt::Error;
pub use core::fmt::{ArgumentV1, Arguments, write, radix, Radix, RadixFmt};

use string;

/// The format function takes a precompiled format string and a list of
/// arguments, to return the resulting formatted string.
///
Expand All @@ -434,3 +434,15 @@ pub fn format(args: Arguments) -> string::String {
let _ = write!(&mut output, "{}", args);
output
}

#[cfg(test)]
mod tests {
use prelude::*;
use fmt;

#[test]
fn test_format() {
let s = fmt::format(format_args!("Hello, {}!", "world"));
assert_eq!(s.as_slice(), "Hello, world!");
}
}
19 changes: 11 additions & 8 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#![cfg_attr(test, feature(test))]
#![cfg_attr(test, allow(deprecated))] // rand

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

#[macro_use]
Expand Down Expand Up @@ -68,6 +69,7 @@ mod bit;
mod btree;
pub mod dlist;
pub mod enum_set;
pub mod fmt;
pub mod ring_buf;
pub mod slice;
pub mod str;
Expand Down Expand Up @@ -107,15 +109,16 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}

#[cfg(not(test))]
mod std {
pub use core::fmt; // necessary for panic!()
pub use core::option; // necessary for panic!()
pub use core::clone; // derive(Clone)
pub use core::cmp; // derive(Eq, Ord, etc.)
pub use core::marker; // derive(Copy)
pub use core::hash; // derive(Hash)
// NOTE: remove after next snapshot
#[cfg(stage0)] pub use core::clone; // derive(Clone)
#[cfg(stage0)] pub use core::cmp; // derive(Eq, Ord, etc.)
#[cfg(stage0)] pub use core::marker; // derive(Copy)
#[cfg(stage0)] pub use core::hash; // derive(Hash)
#[cfg(stage0)] pub use core::iter;
#[cfg(stage0)] pub use core::fmt; // necessary for panic!()
#[cfg(stage0)] pub use core::option; // necessary for panic!()

pub use core::ops; // RangeFull
// for-loops
pub use core::iter;
}

#[cfg(test)]
Expand Down
16 changes: 16 additions & 0 deletions src/libcollections/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ macro_rules! vec {
);
($($x:expr,)*) => (vec![$($x),*])
}

/// Use the syntax described in `std::fmt` to create a value of type `String`.
/// See `std::fmt` for more information.
///
/// # Example
///
/// ```
/// format!("test");
/// format!("hello {}", "world!");
/// format!("x = {}, y = {y}", 10, y = 30);
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! format {
($($arg:tt)*) => ($crate::fmt::format(format_args!($($arg)*)))
}
4 changes: 2 additions & 2 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use core::ops::{Index, IndexMut};
use core::ptr;
use core::raw::Slice as RawSlice;

use std::hash::{Writer, Hash, Hasher};
use std::cmp;
use core::hash::{Writer, Hash, Hasher};
use core::cmp;

use alloc::heap;

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use num::{ToPrimitive, Int};
use ops::{Add, Deref, FnMut};
use option::Option;
use option::Option::{Some, None};
use std::marker::Sized;
use marker::Sized;
use usize;

/// An interface for dealing with "external iterators". These types of iterators
Expand Down
25 changes: 17 additions & 8 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]

#![feature(no_std)]
#![no_std]
#![allow(raw_pointer_derive)]
#![deny(missing_docs)]
Expand Down Expand Up @@ -148,17 +149,25 @@ mod array;
mod core {
pub use panicking;
pub use fmt;
#[cfg(not(stage0))] pub use clone;
#[cfg(not(stage0))] pub use cmp;
#[cfg(not(stage0))] pub use hash;
#[cfg(not(stage0))] pub use marker;
#[cfg(not(stage0))] pub use option;
#[cfg(not(stage0))] pub use iter;
}

#[doc(hidden)]
mod std {
pub use clone;
pub use cmp;
pub use fmt;
pub use hash;
pub use marker;
// NOTE: remove after next snapshot
#[cfg(stage0)] pub use clone;
#[cfg(stage0)] pub use cmp;
#[cfg(stage0)] pub use hash;
#[cfg(stage0)] pub use marker;
#[cfg(stage0)] pub use option;
#[cfg(stage0)] pub use fmt;
#[cfg(stage0)] pub use iter;

// range syntax
pub use ops;
pub use option;
// for-loops
pub use iter;
}
4 changes: 3 additions & 1 deletion src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![cfg_attr(not(feature = "cargo-build"), staged_api)]
#![cfg_attr(not(feature = "cargo-build"), feature(core))]
#![feature(int_uint)]
#![feature(no_std)]
#![no_std]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
Expand Down Expand Up @@ -5729,8 +5730,9 @@ pub fn issue_14344_workaround() {} // FIXME #14344 force linkage to happen corre

#[test] fn work_on_windows() { } // FIXME #10872 needed for a happy windows

// NOTE: remove after next snapshot
#[doc(hidden)]
#[cfg(not(test))]
#[cfg(all(stage0, not(test)))]
mod std {
pub use core::marker;
}
4 changes: 3 additions & 1 deletion src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(int_uint)]
#![feature(no_std)]
#![no_std]
#![unstable(feature = "rand")]
#![feature(staged_api)]
Expand Down Expand Up @@ -496,7 +497,8 @@ pub struct Open01<F>(pub F);
/// ```
pub struct Closed01<F>(pub F);

#[cfg(not(test))]
// NOTE: remove after next snapshot
#[cfg(all(stage0, not(test)))]
mod std {
pub use core::{option, fmt}; // panic!()
pub use core::clone; // derive Clone
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_bitflags/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![feature(staged_api)]
#![staged_api]
#![crate_type = "rlib"]
#![feature(no_std)]
#![no_std]
#![unstable(feature = "rustc_private")]

Expand Down Expand Up @@ -281,6 +282,13 @@ macro_rules! bitflags {
};
}

// This is a no_std crate. So the test code's invocation of #[derive] etc, via
// bitflags!, will use names from the underlying crates.
#[cfg(test)]
mod core {
pub use std::{fmt, hash, clone, cmp, marker, option};
}

#[cfg(test)]
#[allow(non_upper_case_globals)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct RH<'a> {
sub: &'a [RH<'a>]
}

static EMPTY_SOURCE_STR: &'static str = "#![no_std]";
static EMPTY_SOURCE_STR: &'static str = "#![feature(no_std)] #![no_std]";

struct ExpectErrorEmitter {
messages: Vec<String>
Expand Down
17 changes: 10 additions & 7 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#![cfg_attr(test, feature(test))]

// Don't link to std. We are std.
#![feature(no_std)]
#![no_std]

#![deny(missing_docs)]
Expand All @@ -137,7 +138,7 @@
extern crate core;

#[macro_use]
#[macro_reexport(vec)]
#[macro_reexport(vec, format)]
extern crate "collections" as core_collections;

#[allow(deprecated)] extern crate "rand" as core_rand;
Expand Down Expand Up @@ -180,6 +181,7 @@ pub use core::error;
#[cfg(not(test))] pub use alloc::boxed;
pub use alloc::rc;

pub use core_collections::fmt;
pub use core_collections::slice;
pub use core_collections::str;
pub use core_collections::string;
Expand Down Expand Up @@ -245,7 +247,6 @@ pub mod thread_local;

pub mod dynamic_lib;
pub mod ffi;
pub mod fmt;
pub mod old_io;
pub mod io;
pub mod os;
Expand Down Expand Up @@ -285,11 +286,12 @@ mod tuple;
// can be resolved within libstd.
#[doc(hidden)]
mod std {
// NOTE: remove after next snapshot
// mods used for deriving
pub use clone;
pub use cmp;
pub use hash;
pub use default;
#[cfg(stage0)] pub use clone;
#[cfg(stage0)] pub use cmp;
#[cfg(stage0)] pub use hash;
#[cfg(stage0)] pub use default;

pub use sync; // used for select!()
pub use error; // used for try!()
Expand All @@ -312,5 +314,6 @@ mod std {

pub use boxed; // used for vec![]
// for-loops
pub use iter;
// NOTE: remove after next snapshot
#[cfg(stage0)] pub use iter;
}
Loading