Skip to content

Commit 74b8740

Browse files
committed
Auto merge of #21988 - kmcallister:no-std, r=sfackler
Fixes #21833. [breaking-change] r? @alexcrichton The tests in #21912 will also need `#[feature(no_std)]`. If you're okay with both PRs, I can merge and test them.
2 parents bfaa1a8 + 312f8bd commit 74b8740

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+489
-171
lines changed

src/doc/reference.md

+6
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,12 @@ The currently implemented features of the reference compiler are:
24672467

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

2470+
* `no_std` - Allows the `#![no_std]` crate attribute, which disables the implicit
2471+
`extern crate std`. This typically requires use of the unstable APIs
2472+
behind the libstd "facade", such as libcore and libcollections. It
2473+
may also cause problems when using syntax extensions, including
2474+
`#[derive]`.
2475+
24702476
If a feature is promoted to a language feature, then all existing programs will
24712477
start to receive compilation warnings about #[feature] directives which enabled
24722478
the new feature (because the directive is no longer necessary). However, if a

src/doc/trpl/unsafe.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ attribute attached to the crate.
433433
```ignore
434434
// a minimal library
435435
#![crate_type="lib"]
436+
#![feature(no_std)]
436437
#![no_std]
437438
# // fn main() {} tricked you, rustdoc!
438439
```
@@ -446,8 +447,8 @@ The function marked `#[start]` is passed the command line parameters
446447
in the same format as C:
447448

448449
```
450+
#![feature(lang_items, start, no_std)]
449451
#![no_std]
450-
#![feature(lang_items, start)]
451452
452453
// Pull in the system libc library for what crt0.o likely requires
453454
extern crate libc;
@@ -473,6 +474,7 @@ correct ABI and the correct name, which requires overriding the
473474
compiler's name mangling too:
474475

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

530532
```
533+
#![feature(lang_items, start, no_std)]
531534
#![no_std]
532-
#![feature(lang_items, start)]
533535
534536
# extern crate libc;
535537
extern crate core;
@@ -576,10 +578,6 @@ extern fn panic_fmt(args: &core::fmt::Arguments,
576578
#[lang = "eh_personality"] extern fn eh_personality() {}
577579
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }
578580
# fn main() {}
579-
# mod std { // for-loops
580-
# pub use core::iter;
581-
# pub use core::option;
582-
# }
583581
```
584582

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

658656
```
657+
#![feature(lang_items, box_syntax, start, no_std)]
659658
#![no_std]
660-
#![feature(lang_items, box_syntax, start)]
661659
662660
extern crate libc;
663661

src/liballoc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
6666
html_root_url = "http://doc.rust-lang.org/nightly/")]
6767

68+
#![feature(no_std)]
6869
#![no_std]
6970
#![feature(lang_items, unsafe_destructor)]
7071
#![feature(box_syntax)]
@@ -126,7 +127,8 @@ pub fn oom() -> ! {
126127
#[doc(hidden)]
127128
pub fn fixme_14344_be_sure_to_link_to_collections() {}
128129

129-
#[cfg(not(test))]
130+
// NOTE: remove after next snapshot
131+
#[cfg(all(stage0, not(test)))]
130132
#[doc(hidden)]
131133
mod std {
132134
pub use core::fmt;

src/libstd/fmt.rs src/libcollections/fmt.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -134,7 +134,7 @@
134134
//! * `E` ⇒ `UpperExp`
135135
//!
136136
//! What this means is that any type of argument which implements the
137-
//! `std::fmt::Binary` trait can then be formatted with `{:b}`. Implementations
137+
//! `fmt::Binary` trait can then be formatted with `{:b}`. Implementations
138138
//! are provided for these traits for a number of primitive types by the
139139
//! standard library as well. If no format is specified (as in `{}` or `{:6}`),
140140
//! then the format trait used is the `Display` trait.
@@ -146,7 +146,7 @@
146146
//! # use std::fmt;
147147
//! # struct Foo; // our custom type
148148
//! # impl fmt::Display for Foo {
149-
//! fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
149+
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
150150
//! # write!(f, "testing, testing")
151151
//! # } }
152152
//! ```
@@ -403,8 +403,6 @@
403403
404404
#![unstable(feature = "std_misc")]
405405

406-
use string;
407-
408406
pub use core::fmt::{Formatter, Result, Writer, rt};
409407
pub use core::fmt::{Show, String, Octal, Binary};
410408
pub use core::fmt::{Display, Debug};
@@ -413,6 +411,8 @@ pub use core::fmt::{LowerExp, UpperExp};
413411
pub use core::fmt::Error;
414412
pub use core::fmt::{ArgumentV1, Arguments, write, radix, Radix, RadixFmt};
415413

414+
use string;
415+
416416
/// The format function takes a precompiled format string and a list of
417417
/// arguments, to return the resulting formatted string.
418418
///
@@ -434,3 +434,15 @@ pub fn format(args: Arguments) -> string::String {
434434
let _ = write!(&mut output, "{}", args);
435435
output
436436
}
437+
438+
#[cfg(test)]
439+
mod tests {
440+
use prelude::*;
441+
use fmt;
442+
443+
#[test]
444+
fn test_format() {
445+
let s = fmt::format(format_args!("Hello, {}!", "world"));
446+
assert_eq!(s.as_slice(), "Hello, world!");
447+
}
448+
}

src/libcollections/lib.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#![cfg_attr(test, feature(test))]
3434
#![cfg_attr(test, allow(deprecated))] // rand
3535

36+
#![feature(no_std)]
3637
#![no_std]
3738

3839
#[macro_use]
@@ -68,6 +69,7 @@ mod bit;
6869
mod btree;
6970
pub mod dlist;
7071
pub mod enum_set;
72+
pub mod fmt;
7173
pub mod ring_buf;
7274
pub mod slice;
7375
pub mod str;
@@ -107,15 +109,16 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}
107109

108110
#[cfg(not(test))]
109111
mod std {
110-
pub use core::fmt; // necessary for panic!()
111-
pub use core::option; // necessary for panic!()
112-
pub use core::clone; // derive(Clone)
113-
pub use core::cmp; // derive(Eq, Ord, etc.)
114-
pub use core::marker; // derive(Copy)
115-
pub use core::hash; // derive(Hash)
112+
// NOTE: remove after next snapshot
113+
#[cfg(stage0)] pub use core::clone; // derive(Clone)
114+
#[cfg(stage0)] pub use core::cmp; // derive(Eq, Ord, etc.)
115+
#[cfg(stage0)] pub use core::marker; // derive(Copy)
116+
#[cfg(stage0)] pub use core::hash; // derive(Hash)
117+
#[cfg(stage0)] pub use core::iter;
118+
#[cfg(stage0)] pub use core::fmt; // necessary for panic!()
119+
#[cfg(stage0)] pub use core::option; // necessary for panic!()
120+
116121
pub use core::ops; // RangeFull
117-
// for-loops
118-
pub use core::iter;
119122
}
120123

121124
#[cfg(test)]

src/libcollections/macros.rs

+16
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ macro_rules! vec {
2222
);
2323
($($x:expr,)*) => (vec![$($x),*])
2424
}
25+
26+
/// Use the syntax described in `std::fmt` to create a value of type `String`.
27+
/// See `std::fmt` for more information.
28+
///
29+
/// # Example
30+
///
31+
/// ```
32+
/// format!("test");
33+
/// format!("hello {}", "world!");
34+
/// format!("x = {}, y = {y}", 10, y = 30);
35+
/// ```
36+
#[macro_export]
37+
#[stable(feature = "rust1", since = "1.0.0")]
38+
macro_rules! format {
39+
($($arg:tt)*) => ($crate::fmt::format(format_args!($($arg)*)))
40+
}

src/libcollections/ring_buf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use core::ops::{Index, IndexMut};
2727
use core::ptr;
2828
use core::raw::Slice as RawSlice;
2929

30-
use std::hash::{Writer, Hash, Hasher};
31-
use std::cmp;
30+
use core::hash::{Writer, Hash, Hasher};
31+
use core::cmp;
3232

3333
use alloc::heap;
3434

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use num::{ToPrimitive, Int};
6767
use ops::{Add, Deref, FnMut};
6868
use option::Option;
6969
use option::Option::{Some, None};
70-
use std::marker::Sized;
70+
use marker::Sized;
7171
use usize;
7272

7373
/// An interface for dealing with "external iterators". These types of iterators

src/libcore/lib.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
html_root_url = "http://doc.rust-lang.org/nightly/",
5757
html_playground_url = "http://play.rust-lang.org/")]
5858

59+
#![feature(no_std)]
5960
#![no_std]
6061
#![allow(raw_pointer_derive)]
6162
#![deny(missing_docs)]
@@ -148,17 +149,25 @@ mod array;
148149
mod core {
149150
pub use panicking;
150151
pub use fmt;
152+
#[cfg(not(stage0))] pub use clone;
153+
#[cfg(not(stage0))] pub use cmp;
154+
#[cfg(not(stage0))] pub use hash;
155+
#[cfg(not(stage0))] pub use marker;
156+
#[cfg(not(stage0))] pub use option;
157+
#[cfg(not(stage0))] pub use iter;
151158
}
152159

153160
#[doc(hidden)]
154161
mod std {
155-
pub use clone;
156-
pub use cmp;
157-
pub use fmt;
158-
pub use hash;
159-
pub use marker;
162+
// NOTE: remove after next snapshot
163+
#[cfg(stage0)] pub use clone;
164+
#[cfg(stage0)] pub use cmp;
165+
#[cfg(stage0)] pub use hash;
166+
#[cfg(stage0)] pub use marker;
167+
#[cfg(stage0)] pub use option;
168+
#[cfg(stage0)] pub use fmt;
169+
#[cfg(stage0)] pub use iter;
170+
171+
// range syntax
160172
pub use ops;
161-
pub use option;
162-
// for-loops
163-
pub use iter;
164173
}

src/liblibc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![cfg_attr(not(feature = "cargo-build"), staged_api)]
1717
#![cfg_attr(not(feature = "cargo-build"), feature(core))]
1818
#![feature(int_uint)]
19+
#![feature(no_std)]
1920
#![no_std]
2021
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2122
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
@@ -5729,8 +5730,9 @@ pub fn issue_14344_workaround() {} // FIXME #14344 force linkage to happen corre
57295730

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

5733+
// NOTE: remove after next snapshot
57325734
#[doc(hidden)]
5733-
#[cfg(not(test))]
5735+
#[cfg(all(stage0, not(test)))]
57345736
mod std {
57355737
pub use core::marker;
57365738
}

src/librand/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
html_root_url = "http://doc.rust-lang.org/nightly/",
2424
html_playground_url = "http://play.rust-lang.org/")]
2525
#![feature(int_uint)]
26+
#![feature(no_std)]
2627
#![no_std]
2728
#![unstable(feature = "rand")]
2829
#![feature(staged_api)]
@@ -496,7 +497,8 @@ pub struct Open01<F>(pub F);
496497
/// ```
497498
pub struct Closed01<F>(pub F);
498499

499-
#[cfg(not(test))]
500+
// NOTE: remove after next snapshot
501+
#[cfg(all(stage0, not(test)))]
500502
mod std {
501503
pub use core::{option, fmt}; // panic!()
502504
pub use core::clone; // derive Clone

src/librustc_bitflags/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(staged_api)]
1313
#![staged_api]
1414
#![crate_type = "rlib"]
15+
#![feature(no_std)]
1516
#![no_std]
1617
#![unstable(feature = "rustc_private")]
1718

@@ -281,6 +282,13 @@ macro_rules! bitflags {
281282
};
282283
}
283284

285+
// This is a no_std crate. So the test code's invocation of #[derive] etc, via
286+
// bitflags!, will use names from the underlying crates.
287+
#[cfg(test)]
288+
mod core {
289+
pub use std::{fmt, hash, clone, cmp, marker, option};
290+
}
291+
284292
#[cfg(test)]
285293
#[allow(non_upper_case_globals)]
286294
mod tests {

src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct RH<'a> {
4343
sub: &'a [RH<'a>]
4444
}
4545

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

4848
struct ExpectErrorEmitter {
4949
messages: Vec<String>

src/libstd/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![cfg_attr(test, feature(test))]
125125

126126
// Don't link to std. We are std.
127+
#![feature(no_std)]
127128
#![no_std]
128129

129130
#![deny(missing_docs)]
@@ -137,7 +138,7 @@
137138
extern crate core;
138139

139140
#[macro_use]
140-
#[macro_reexport(vec)]
141+
#[macro_reexport(vec, format)]
141142
extern crate "collections" as core_collections;
142143

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

184+
pub use core_collections::fmt;
183185
pub use core_collections::slice;
184186
pub use core_collections::str;
185187
pub use core_collections::string;
@@ -245,7 +247,6 @@ pub mod thread_local;
245247

246248
pub mod dynamic_lib;
247249
pub mod ffi;
248-
pub mod fmt;
249250
pub mod old_io;
250251
pub mod io;
251252
pub mod os;
@@ -285,11 +286,12 @@ mod tuple;
285286
// can be resolved within libstd.
286287
#[doc(hidden)]
287288
mod std {
289+
// NOTE: remove after next snapshot
288290
// mods used for deriving
289-
pub use clone;
290-
pub use cmp;
291-
pub use hash;
292-
pub use default;
291+
#[cfg(stage0)] pub use clone;
292+
#[cfg(stage0)] pub use cmp;
293+
#[cfg(stage0)] pub use hash;
294+
#[cfg(stage0)] pub use default;
293295

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

313315
pub use boxed; // used for vec![]
314316
// for-loops
315-
pub use iter;
317+
// NOTE: remove after next snapshot
318+
#[cfg(stage0)] pub use iter;
316319
}

0 commit comments

Comments
 (0)