Skip to content

Commit 6e04763

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 178589 b: refs/heads/try c: ccf8fed h: refs/heads/master i: 178587: 385d159 v: v3
1 parent a7d7cf4 commit 6e04763

40 files changed

+363
-101
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 336c8d2e9c6b276b162bdb3edd43706372e6eddd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 474b324eda10440d6568ef872a7307d38e7de95b
5-
refs/heads/try: 6cebe475d1bcebd632992350f8a4a46981b12213
5+
refs/heads/try: ccf8fedf1cffcb8f6f3581d53d220039e192fe77
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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

branches/try/src/liballoc/lib.rs

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

127-
#[cfg(not(test))]
127+
// NOTE: remove after next snapshot
128+
#[cfg(all(stage0, not(test)))]
128129
#[doc(hidden)]
129130
mod std {
130131
pub use core::fmt;

branches/try/src/libcollections/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,16 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {}
109109

110110
#[cfg(not(test))]
111111
mod std {
112-
pub use core::fmt; // necessary for panic!()
113-
pub use core::option; // necessary for panic!()
114-
pub use core::clone; // derive(Clone)
115-
pub use core::cmp; // derive(Eq, Ord, etc.)
116-
pub use core::marker; // derive(Copy)
117-
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+
118121
pub use core::ops; // RangeFull
119-
// for-loops
120-
pub use core::iter;
121122
}
122123

123124
#[cfg(test)]

branches/try/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::string::String::format(format_args!($($arg)*)))
40+
}

branches/try/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

branches/try/src/libcollections/string.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,29 @@ impl String {
671671
pub fn clear(&mut self) {
672672
self.vec.clear()
673673
}
674+
675+
/// The format function takes a precompiled format string and a list of
676+
/// arguments, to return the resulting formatted string.
677+
///
678+
/// # Arguments
679+
///
680+
/// * args - a structure of arguments generated via the `format_args!` macro.
681+
///
682+
/// # Example
683+
///
684+
/// ```rust
685+
/// let s = String::format(format_args!("Hello, {}!", "world"));
686+
/// assert_eq!(s, "Hello, world!".to_string());
687+
/// ```
688+
#[unstable(feature = "collections",
689+
reason = "duplicates std::fmt::format, only needed when libstd is missing")]
690+
pub fn format(args: fmt::Arguments) -> String {
691+
// FIXME #21826
692+
use core::fmt::Writer;
693+
let mut output = String::new();
694+
let _ = write!(&mut output, "{}", args);
695+
output
696+
}
674697
}
675698

676699
impl FromUtf8Error {
@@ -1348,6 +1371,12 @@ mod tests {
13481371
assert_eq!(s, d);
13491372
}
13501373

1374+
#[test]
1375+
fn test_format() {
1376+
let s = format_args!(String::format, "Hello, {}!", "world");
1377+
assert_eq!(s.as_slice(), "Hello, world!");
1378+
}
1379+
13511380
#[bench]
13521381
fn bench_with_capacity(b: &mut Bencher) {
13531382
b.iter(|| {

branches/try/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

branches/try/src/libcore/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,25 @@ mod array;
149149
mod core {
150150
pub use panicking;
151151
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;
152158
}
153159

154160
#[doc(hidden)]
155161
mod std {
156-
pub use clone;
157-
pub use cmp;
158-
pub use fmt;
159-
pub use hash;
160-
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
161172
pub use ops;
162-
pub use option;
163-
// for-loops
164-
pub use iter;
165173
}

branches/try/src/liblibc/lib.rs

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

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

5104+
// NOTE: remove after next snapshot
51045105
#[doc(hidden)]
5105-
#[cfg(not(test))]
5106+
#[cfg(all(stage0, not(test)))]
51065107
mod std {
51075108
pub use core::marker;
51085109
}

branches/try/src/librand/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ pub struct Open01<F>(pub F);
493493
/// ```
494494
pub struct Closed01<F>(pub F);
495495

496-
#[cfg(not(test))]
496+
// NOTE: remove after next snapshot
497+
#[cfg(all(stage0, not(test)))]
497498
mod std {
498499
pub use core::{option, fmt}; // panic!()
499500
pub use core::clone; // derive Clone

branches/try/src/libstd/fmt.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,5 @@ pub use core::fmt::{argument, argumentuint};
434434
/// ```
435435
#[stable(feature = "rust1", since = "1.0.0")]
436436
pub fn format(args: Arguments) -> string::String {
437-
let mut output = string::String::new();
438-
let _ = write!(&mut output, "{}", args);
439-
output
437+
string::String::format(args)
440438
}

branches/try/src/libstd/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extern crate log;
139139
extern crate core;
140140

141141
#[macro_use]
142-
#[macro_reexport(vec)]
142+
#[macro_reexport(vec, format)]
143143
extern crate "collections" as core_collections;
144144

145145
extern crate "rand" as core_rand;
@@ -284,11 +284,12 @@ mod tuple;
284284
// can be resolved within libstd.
285285
#[doc(hidden)]
286286
mod std {
287+
// NOTE: remove after next snapshot
287288
// mods used for deriving
288-
pub use clone;
289-
pub use cmp;
290-
pub use hash;
291-
pub use default;
289+
#[cfg(stage0)] pub use clone;
290+
#[cfg(stage0)] pub use cmp;
291+
#[cfg(stage0)] pub use hash;
292+
#[cfg(stage0)] pub use default;
292293

293294
pub use sync; // used for select!()
294295
pub use error; // used for try!()
@@ -311,5 +312,6 @@ mod std {
311312

312313
pub use boxed; // used for vec![]
313314
// for-loops
314-
pub use iter;
315+
// NOTE: remove after next snapshot
316+
#[cfg(stage0)] pub use iter;
315317
}

branches/try/src/libstd/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ macro_rules! panic {
7070
/// format!("hello {}", "world!");
7171
/// format!("x = {}, y = {y}", 10, y = 30);
7272
/// ```
73+
#[cfg(stage0)] // NOTE: remove after snapshot
7374
#[macro_export]
7475
#[stable(feature = "rust1", since = "1.0.0")]
7576
macro_rules! format {

branches/try/src/libsyntax/ext/base.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ pub struct ExtCtxt<'a> {
544544
pub cfg: ast::CrateConfig,
545545
pub backtrace: ExpnId,
546546
pub ecfg: expand::ExpansionConfig,
547+
pub use_std: bool,
547548

548549
pub mod_path: Vec<ast::Ident> ,
549550
pub trace_mac: bool,
@@ -563,6 +564,7 @@ impl<'a> ExtCtxt<'a> {
563564
backtrace: NO_EXPANSION,
564565
mod_path: Vec::new(),
565566
ecfg: ecfg,
567+
use_std: true,
566568
trace_mac: false,
567569
exported_macros: Vec::new(),
568570
syntax_env: env,
@@ -737,6 +739,9 @@ impl<'a> ExtCtxt<'a> {
737739
pub fn ident_of(&self, st: &str) -> ast::Ident {
738740
str_to_ident(st)
739741
}
742+
pub fn ident_of_std(&self, st: &str) -> ast::Ident {
743+
self.ident_of(if self.use_std { "std" } else { st })
744+
}
740745
pub fn name_of(&self, st: &str) -> ast::Name {
741746
token::intern(st)
742747
}

0 commit comments

Comments
 (0)