Skip to content

Commit 67350bc

Browse files
author
Keegan McAllister
committed
Don't use std:: paths in syntax extensions when compiling a #![no_std] crate
Fixes #16803. Fixes #14342. Fixes half of #21827 -- slice syntax is still broken.
1 parent 74eef05 commit 67350bc

Some content is hidden

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

41 files changed

+413
-145
lines changed

src/doc/trpl/unsafe.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,6 @@ extern fn panic_fmt(args: &core::fmt::Arguments,
576576
#[lang = "eh_personality"] extern fn eh_personality() {}
577577
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }
578578
# fn main() {}
579-
# mod std { // for-loops
580-
# pub use core::iter;
581-
# pub use core::option;
582-
# }
583579
```
584580

585581
Note that there is one extra lang item here which differs from the examples

src/liballoc/lib.rs

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

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

src/libcollections/fmt.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Formatting support for `String`.
12+
//!
13+
//! See `core::fmt` and `std::fmt` for full documentation on string
14+
//! formatting.
15+
16+
#![stable(feature = "rust1", since = "1.0.0")]
17+
18+
use core::fmt;
19+
20+
use string;
21+
22+
/// The format function takes a precompiled format string and a list of
23+
/// arguments, to return the resulting formatted string.
24+
///
25+
/// # Arguments
26+
///
27+
/// * args - a structure of arguments generated via the `format_args!` macro.
28+
///
29+
/// # Example
30+
///
31+
/// ```rust
32+
/// use std::fmt;
33+
///
34+
/// let s = fmt::format(format_args!("Hello, {}!", "world"));
35+
/// assert_eq!(s, "Hello, world!".to_string());
36+
/// ```
37+
#[stable(feature = "rust1", since = "1.0.0")]
38+
pub fn format(args: fmt::Arguments) -> string::String {
39+
// FIXME #21826
40+
use core::fmt::Writer;
41+
let mut output = string::String::new();
42+
let _ = write!(&mut output, "{}", args);
43+
output
44+
}
45+
46+
#[cfg(test)]
47+
mod tests {
48+
use prelude::*;
49+
use fmt;
50+
51+
#[test]
52+
fn test_format() {
53+
let s = fmt::format(format_args!("Hello, {}!", "world"));
54+
assert_eq!(s.as_slice(), "Hello, world!");
55+
}
56+
}

src/libcollections/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod bit;
6868
mod btree;
6969
pub mod dlist;
7070
pub mod enum_set;
71+
pub mod fmt;
7172
pub mod ring_buf;
7273
pub mod slice;
7374
pub mod str;
@@ -107,15 +108,16 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}
107108

108109
#[cfg(not(test))]
109110
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)
111+
// NOTE: remove after next snapshot
112+
#[cfg(stage0)] pub use core::clone; // derive(Clone)
113+
#[cfg(stage0)] pub use core::cmp; // derive(Eq, Ord, etc.)
114+
#[cfg(stage0)] pub use core::marker; // derive(Copy)
115+
#[cfg(stage0)] pub use core::hash; // derive(Hash)
116+
#[cfg(stage0)] pub use core::iter;
117+
#[cfg(stage0)] pub use core::fmt; // necessary for panic!()
118+
#[cfg(stage0)] pub use core::option; // necessary for panic!()
119+
116120
pub use core::ops; // RangeFull
117-
// for-loops
118-
pub use core::iter;
119121
}
120122

121123
#[cfg(test)]

src/libcollections/macros.rs

Lines changed: 16 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,25 @@ mod array;
148148
mod core {
149149
pub use panicking;
150150
pub use fmt;
151+
#[cfg(not(stage0))] pub use clone;
152+
#[cfg(not(stage0))] pub use cmp;
153+
#[cfg(not(stage0))] pub use hash;
154+
#[cfg(not(stage0))] pub use marker;
155+
#[cfg(not(stage0))] pub use option;
156+
#[cfg(not(stage0))] pub use iter;
151157
}
152158

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

src/liblibc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5729,8 +5729,9 @@ pub fn issue_14344_workaround() {} // FIXME #14344 force linkage to happen corre
57295729

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

5732+
// NOTE: remove after next snapshot
57325733
#[doc(hidden)]
5733-
#[cfg(not(test))]
5734+
#[cfg(all(stage0, not(test)))]
57345735
mod std {
57355736
pub use core::marker;
57365737
}

src/librand/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ pub struct Open01<F>(pub F);
496496
/// ```
497497
pub struct Closed01<F>(pub F);
498498

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

0 commit comments

Comments
 (0)