Skip to content

Commit b4f0b75

Browse files
committed
---
yaml --- r: 190319 b: refs/heads/auto c: b1eadf3 h: refs/heads/master i: 190317: ca9e6ee 190315: a5c96fc 190311: 2240ef8 190303: b89cfc3 v: v3
1 parent 71f8b32 commit b4f0b75

File tree

20 files changed

+472
-406
lines changed

20 files changed

+472
-406
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: b94bcbcdcf89b03a879f9f16f642914d1b55243f
13+
refs/heads/auto: b1eadf3f1d2a350ed3c5144d69f1c4841e9f5f34
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#![feature(staged_api)]
3838
#![feature(exit_status)]
3939
#![feature(io)]
40-
#![feature(set_panic)]
40+
#![feature(set_stdio)]
4141

4242
extern crate arena;
4343
extern crate flate;

branches/auto/src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#![feature(core)]
2727
#![feature(exit_status)]
2828
#![feature(int_uint)]
29-
#![feature(set_panic)]
29+
#![feature(set_stdio)]
3030
#![feature(libc)]
3131
#![feature(old_path)]
3232
#![feature(rustc_private)]

branches/auto/src/libstd/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub fn get_exit_status() -> i32 {
452452
EXIT_STATUS.load(Ordering::SeqCst) as i32
453453
}
454454

455-
/// An iterator over the arguments of a process, yielding an `String` value
455+
/// An iterator over the arguments of a process, yielding a `String` value
456456
/// for each argument.
457457
///
458458
/// This structure is created through the `std::env::args` method.

branches/auto/src/libstd/io/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
// except according to those terms.
1010

1111
//! Traits, helpers, and type definitions for core I/O functionality.
12-
//!
13-
//! > **NOTE**: This module is very much a work in progress and is under active
14-
//! > development. At this time it is still recommended to use the `old_io`
15-
//! > module while the details of this module shake out.
1612
1713
#![stable(feature = "rust1", since = "1.0.0")]
1814

@@ -37,10 +33,10 @@ pub use self::buffered::IntoInnerError;
3733
pub use self::cursor::Cursor;
3834
pub use self::error::{Result, Error, ErrorKind};
3935
pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat};
40-
pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr};
36+
pub use self::stdio::{stdin, stdout, stderr, _print, Stdin, Stdout, Stderr};
4137
pub use self::stdio::{StdoutLock, StderrLock, StdinLock};
4238
#[doc(no_inline, hidden)]
43-
pub use self::stdio::set_panic;
39+
pub use self::stdio::{set_panic, set_print};
4440

4541
#[macro_use] mod lazy;
4642

branches/auto/src/libstd/io/stdio.rs

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,38 @@
1111
use prelude::v1::*;
1212
use io::prelude::*;
1313

14+
use cell::RefCell;
1415
use cmp;
1516
use fmt;
1617
use io::lazy::Lazy;
1718
use io::{self, BufReader, LineWriter};
1819
use sync::{Arc, Mutex, MutexGuard};
1920
use sys::stdio;
2021

22+
/// Stdout used by print! and println! macroses
23+
thread_local! {
24+
static LOCAL_STDOUT: RefCell<Option<Box<Write + Send>>> = {
25+
RefCell::new(None)
26+
}
27+
}
28+
2129
/// A handle to a raw instance of the standard input stream of this process.
2230
///
2331
/// This handle is not synchronized or buffered in any fashion. Constructed via
24-
/// the `std::io::stdin_raw` function.
25-
pub struct StdinRaw(stdio::Stdin);
32+
/// the `std::io::stdio::stdin_raw` function.
33+
struct StdinRaw(stdio::Stdin);
2634

2735
/// A handle to a raw instance of the standard output stream of this process.
2836
///
2937
/// This handle is not synchronized or buffered in any fashion. Constructed via
30-
/// the `std::io::stdout_raw` function.
31-
pub struct StdoutRaw(stdio::Stdout);
38+
/// the `std::io::stdio::stdout_raw` function.
39+
struct StdoutRaw(stdio::Stdout);
3240

3341
/// A handle to a raw instance of the standard output stream of this process.
3442
///
3543
/// This handle is not synchronized or buffered in any fashion. Constructed via
36-
/// the `std::io::stderr_raw` function.
37-
pub struct StderrRaw(stdio::Stderr);
44+
/// the `std::io::stdio::stderr_raw` function.
45+
struct StderrRaw(stdio::Stderr);
3846

3947
/// Construct a new raw handle to the standard input of this process.
4048
///
@@ -43,7 +51,7 @@ pub struct StderrRaw(stdio::Stderr);
4351
/// handles is **not** available to raw handles returned from this function.
4452
///
4553
/// The returned handle has no external synchronization or buffering.
46-
pub fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) }
54+
fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) }
4755

4856
/// Construct a new raw handle to the standard input stream of this process.
4957
///
@@ -54,7 +62,7 @@ pub fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) }
5462
///
5563
/// The returned handle has no external synchronization or buffering layered on
5664
/// top.
57-
pub fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) }
65+
fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) }
5866

5967
/// Construct a new raw handle to the standard input stream of this process.
6068
///
@@ -63,7 +71,7 @@ pub fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) }
6371
///
6472
/// The returned handle has no external synchronization or buffering layered on
6573
/// top.
66-
pub fn stderr_raw() -> StderrRaw { StderrRaw(stdio::Stderr::new()) }
74+
fn stderr_raw() -> StderrRaw { StderrRaw(stdio::Stderr::new()) }
6775

6876
impl Read for StdinRaw {
6977
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) }
@@ -109,9 +117,6 @@ pub struct StdinLock<'a> {
109117
/// The `Read` trait is implemented for the returned value but the `BufRead`
110118
/// trait is not due to the global nature of the standard input stream. The
111119
/// locked version, `StdinLock`, implements both `Read` and `BufRead`, however.
112-
///
113-
/// To avoid locking and buffering altogether, it is recommended to use the
114-
/// `stdin_raw` constructor.
115120
#[stable(feature = "rust1", since = "1.0.0")]
116121
pub fn stdin() -> Stdin {
117122
static INSTANCE: Lazy<Mutex<BufReader<StdinRaw>>> = lazy_init!(stdin_init);
@@ -224,9 +229,6 @@ pub struct StdoutLock<'a> {
224229
/// provided via the `lock` method.
225230
///
226231
/// The returned handle implements the `Write` trait.
227-
///
228-
/// To avoid locking and buffering altogether, it is recommended to use the
229-
/// `stdout_raw` constructor.
230232
#[stable(feature = "rust1", since = "1.0.0")]
231233
pub fn stdout() -> Stdout {
232234
static INSTANCE: Lazy<Mutex<LineWriter<StdoutRaw>>> = lazy_init!(stdout_init);
@@ -297,9 +299,6 @@ pub struct StderrLock<'a> {
297299
/// this function. No handles are buffered, however.
298300
///
299301
/// The returned handle implements the `Write` trait.
300-
///
301-
/// To avoid locking altogether, it is recommended to use the `stderr_raw`
302-
/// constructor.
303302
#[stable(feature = "rust1", since = "1.0.0")]
304303
pub fn stderr() -> Stderr {
305304
static INSTANCE: Lazy<Mutex<StderrRaw>> = lazy_init!(stderr_init);
@@ -347,15 +346,15 @@ impl<'a> Write for StderrLock<'a> {
347346
fn flush(&mut self) -> io::Result<()> { self.inner.flush() }
348347
}
349348

350-
/// Resets the task-local stdout handle to the specified writer
349+
/// Resets the task-local stderr handle to the specified writer
351350
///
352-
/// This will replace the current task's stdout handle, returning the old
353-
/// handle. All future calls to `print` and friends will emit their output to
351+
/// This will replace the current task's stderr handle, returning the old
352+
/// handle. All future calls to `panic!` and friends will emit their output to
354353
/// this specified handle.
355354
///
356355
/// Note that this does not need to be called for all new tasks; the default
357-
/// output handle is to the process's stdout stream.
358-
#[unstable(feature = "set_panic",
356+
/// output handle is to the process's stderr stream.
357+
#[unstable(feature = "set_stdio",
359358
reason = "this function may disappear completely or be replaced \
360359
with a more general mechanism")]
361360
#[doc(hidden)]
@@ -369,3 +368,37 @@ pub fn set_panic(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
369368
Some(s)
370369
})
371370
}
371+
372+
/// Resets the task-local stdout handle to the specified writer
373+
///
374+
/// This will replace the current task's stdout handle, returning the old
375+
/// handle. All future calls to `print!` and friends will emit their output to
376+
/// this specified handle.
377+
///
378+
/// Note that this does not need to be called for all new tasks; the default
379+
/// output handle is to the process's stdout stream.
380+
#[unstable(feature = "set_stdio",
381+
reason = "this function may disappear completely or be replaced \
382+
with a more general mechanism")]
383+
#[doc(hidden)]
384+
pub fn set_print(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
385+
use mem;
386+
LOCAL_STDOUT.with(move |slot| {
387+
mem::replace(&mut *slot.borrow_mut(), Some(sink))
388+
}).and_then(|mut s| {
389+
let _ = s.flush();
390+
Some(s)
391+
})
392+
}
393+
394+
#[unstable(feature = "print",
395+
reason = "implementation detail which may disappear or be replaced at any time")]
396+
#[doc(hidden)]
397+
pub fn _print(args: fmt::Arguments) {
398+
if let Err(e) = LOCAL_STDOUT.with(|s| match s.borrow_mut().as_mut() {
399+
Some(w) => w.write_fmt(args),
400+
None => stdout().write_fmt(args)
401+
}) {
402+
panic!("failed printing to stdout: {}", e);
403+
}
404+
}

branches/auto/src/libstd/macros.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ macro_rules! panic {
6060
});
6161
}
6262

63+
/// Macro for printing to the standard output.
64+
///
6365
/// Equivalent to the `println!` macro except that a newline is not printed at
6466
/// the end of the message.
6567
#[macro_export]
6668
#[stable(feature = "rust1", since = "1.0.0")]
69+
#[allow_internal_unstable]
6770
macro_rules! print {
68-
($($arg:tt)*) => ($crate::old_io::stdio::print_args(format_args!($($arg)*)))
71+
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
6972
}
7073

71-
/// Macro for printing to a task's stdout handle.
74+
/// Macro for printing to the standard output.
7275
///
73-
/// Each task can override its stdout handle via `std::old_io::stdio::set_stdout`.
74-
/// The syntax of this macro is the same as that used for `format!`. For more
75-
/// information, see `std::fmt` and `std::old_io::stdio`.
76+
/// Use the `format!` syntax to write data to the standard output.
77+
/// See `std::fmt` for more information.
7678
///
7779
/// # Examples
7880
///
@@ -83,7 +85,8 @@ macro_rules! print {
8385
#[macro_export]
8486
#[stable(feature = "rust1", since = "1.0.0")]
8587
macro_rules! println {
86-
($($arg:tt)*) => ($crate::old_io::stdio::println_args(format_args!($($arg)*)))
88+
($fmt:expr) => (print!(concat!($fmt, "\n")));
89+
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
8790
}
8891

8992
/// Helper macro for unwrapping `Result` values while returning early with an

branches/auto/src/libstd/old_io/stdio.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,4 @@ mod tests {
535535
stdout();
536536
stderr();
537537
}
538-
539-
#[test]
540-
fn capture_stdout() {
541-
use old_io::{ChanReader, ChanWriter};
542-
543-
let (tx, rx) = channel();
544-
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
545-
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
546-
let _t = thread::spawn(move|| {
547-
set_stdout(Box::new(w));
548-
println!("hello!");
549-
});
550-
assert_eq!(r.read_to_string().unwrap(), "hello!\n");
551-
}
552538
}

branches/auto/src/libstd/os.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> {
210210

211211
#[cfg(unix)]
212212
fn byteify(s: OsString) -> Vec<u8> {
213-
use os::unix::*;
213+
use os::unix::prelude::*;
214214
s.into_vec()
215215
}
216216
#[cfg(windows)]
@@ -238,7 +238,7 @@ fn byteify(s: OsString) -> Vec<u8> {
238238
pub fn setenv<T: BytesContainer>(n: &str, v: T) {
239239
#[cfg(unix)]
240240
fn _setenv(n: &str, v: &[u8]) {
241-
use os::unix::*;
241+
use os::unix::prelude::*;
242242
let v: OsString = OsStringExt::from_vec(v.to_vec());
243243
env::set_var(n, &v)
244244
}
@@ -1705,13 +1705,13 @@ mod tests {
17051705

17061706
#[cfg(not(windows))]
17071707
fn get_fd(file: &File) -> libc::c_int {
1708-
use os::unix::AsRawFd;
1708+
use os::unix::prelude::*;
17091709
file.as_raw_fd()
17101710
}
17111711

17121712
#[cfg(windows)]
17131713
fn get_fd(file: &File) -> libc::HANDLE {
1714-
use os::windows::AsRawHandle;
1714+
use os::windows::prelude::*;
17151715
file.as_raw_handle()
17161716
}
17171717

branches/auto/src/libstd/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
//!
8787
//! * Occurrences of `.` are normalized away, *except* if they are at
8888
//! the beginning of the path (in which case they are often meaningful
89-
//! in terms of path searching). So, fore xample, `a/./b`, `a/b/`,
90-
//! `/a/b/.` and `a/b` all ahve components `a` and `b`, but `./a/b`
89+
//! in terms of path searching). So, for example, `a/./b`, `a/b/`,
90+
//! `/a/b/.` and `a/b` all have components `a` and `b`, but `./a/b`
9191
//! has a leading current directory component.
9292
//!
9393
//! No other normalization takes place by default. In particular,

branches/auto/src/libstd/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ mod tests {
573573
#[cfg(all(unix, not(target_os="android")))]
574574
#[test]
575575
fn signal_reported_right() {
576-
use os::unix::ExitStatusExt;
576+
use os::unix::process::ExitStatusExt;
577577

578578
let p = Command::new("/bin/sh").arg("-c").arg("kill -9 $$").spawn();
579579
assert!(p.is_ok());
@@ -633,7 +633,7 @@ mod tests {
633633
#[cfg(all(unix, not(target_os="android")))]
634634
#[test]
635635
fn uid_works() {
636-
use os::unix::*;
636+
use os::unix::prelude::*;
637637
use libc;
638638
let mut p = Command::new("/bin/sh")
639639
.arg("-c").arg("true")
@@ -646,7 +646,7 @@ mod tests {
646646
#[cfg(all(unix, not(target_os="android")))]
647647
#[test]
648648
fn uid_to_root_fails() {
649-
use os::unix::*;
649+
use os::unix::prelude::*;
650650
use libc;
651651

652652
// if we're already root, this isn't a valid test. Most of the bots run

0 commit comments

Comments
 (0)