Skip to content

Commit 13ca3d4

Browse files
committed
---
yaml --- r: 190298 b: refs/heads/master c: d14728a h: refs/heads/master v: v3
1 parent 5b286c1 commit 13ca3d4

File tree

23 files changed

+422
-479
lines changed

23 files changed

+422
-479
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: b1eadf3f1d2a350ed3c5144d69f1c4841e9f5f34
2+
refs/heads/master: d14728ad28e07ec09f76f5c956b63bfaec82ad7c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 270a677d4d698916f5ad103f0afc3c070b8dbeb4
55
refs/heads/try: 1c28ab65017d74fc13d003f7c7a73d1a48e5406f

trunk/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_stdio)]
40+
#![feature(set_panic)]
4141

4242
extern crate arena;
4343
extern crate flate;

trunk/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_stdio)]
29+
#![feature(set_panic)]
3030
#![feature(libc)]
3131
#![feature(old_path)]
3232
#![feature(rustc_private)]

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

trunk/src/libstd/io/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
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.
1216
1317
#![stable(feature = "rust1", since = "1.0.0")]
1418

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

4145
#[macro_use] mod lazy;
4246

trunk/src/libstd/io/stdio.rs

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

14-
use cell::RefCell;
1514
use cmp;
1615
use fmt;
1716
use io::lazy::Lazy;
1817
use io::{self, BufReader, LineWriter};
1918
use sync::{Arc, Mutex, MutexGuard};
2019
use sys::stdio;
2120

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-
2921
/// A handle to a raw instance of the standard input stream of this process.
3022
///
3123
/// This handle is not synchronized or buffered in any fashion. Constructed via
32-
/// the `std::io::stdio::stdin_raw` function.
33-
struct StdinRaw(stdio::Stdin);
24+
/// the `std::io::stdin_raw` function.
25+
pub struct StdinRaw(stdio::Stdin);
3426

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

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

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

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

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

7668
impl Read for StdinRaw {
7769
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) }
@@ -117,6 +109,9 @@ pub struct StdinLock<'a> {
117109
/// The `Read` trait is implemented for the returned value but the `BufRead`
118110
/// trait is not due to the global nature of the standard input stream. The
119111
/// 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.
120115
#[stable(feature = "rust1", since = "1.0.0")]
121116
pub fn stdin() -> Stdin {
122117
static INSTANCE: Lazy<Mutex<BufReader<StdinRaw>>> = lazy_init!(stdin_init);
@@ -229,6 +224,9 @@ pub struct StdoutLock<'a> {
229224
/// provided via the `lock` method.
230225
///
231226
/// 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.
232230
#[stable(feature = "rust1", since = "1.0.0")]
233231
pub fn stdout() -> Stdout {
234232
static INSTANCE: Lazy<Mutex<LineWriter<StdoutRaw>>> = lazy_init!(stdout_init);
@@ -299,6 +297,9 @@ pub struct StderrLock<'a> {
299297
/// this function. No handles are buffered, however.
300298
///
301299
/// The returned handle implements the `Write` trait.
300+
///
301+
/// To avoid locking altogether, it is recommended to use the `stderr_raw`
302+
/// constructor.
302303
#[stable(feature = "rust1", since = "1.0.0")]
303304
pub fn stderr() -> Stderr {
304305
static INSTANCE: Lazy<Mutex<StderrRaw>> = lazy_init!(stderr_init);
@@ -346,59 +347,25 @@ impl<'a> Write for StderrLock<'a> {
346347
fn flush(&mut self) -> io::Result<()> { self.inner.flush() }
347348
}
348349

349-
/// Resets the task-local stderr handle to the specified writer
350-
///
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
353-
/// this specified handle.
354-
///
355-
/// Note that this does not need to be called for all new tasks; the default
356-
/// output handle is to the process's stderr stream.
357-
#[unstable(feature = "set_stdio",
358-
reason = "this function may disappear completely or be replaced \
359-
with a more general mechanism")]
360-
#[doc(hidden)]
361-
pub fn set_panic(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
362-
use panicking::LOCAL_STDERR;
363-
use mem;
364-
LOCAL_STDERR.with(move |slot| {
365-
mem::replace(&mut *slot.borrow_mut(), Some(sink))
366-
}).and_then(|mut s| {
367-
let _ = s.flush();
368-
Some(s)
369-
})
370-
}
371-
372350
/// Resets the task-local stdout handle to the specified writer
373351
///
374352
/// 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
353+
/// handle. All future calls to `print` and friends will emit their output to
376354
/// this specified handle.
377355
///
378356
/// Note that this does not need to be called for all new tasks; the default
379357
/// output handle is to the process's stdout stream.
380-
#[unstable(feature = "set_stdio",
358+
#[unstable(feature = "set_panic",
381359
reason = "this function may disappear completely or be replaced \
382360
with a more general mechanism")]
383361
#[doc(hidden)]
384-
pub fn set_print(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
362+
pub fn set_panic(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
363+
use panicking::LOCAL_STDERR;
385364
use mem;
386-
LOCAL_STDOUT.with(move |slot| {
365+
LOCAL_STDERR.with(move |slot| {
387366
mem::replace(&mut *slot.borrow_mut(), Some(sink))
388367
}).and_then(|mut s| {
389368
let _ = s.flush();
390369
Some(s)
391370
})
392371
}
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-
}

trunk/src/libstd/macros.rs

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

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

74-
/// Macro for printing to the standard output.
71+
/// Macro for printing to a task's stdout handle.
7572
///
76-
/// Use the `format!` syntax to write data to the standard output.
77-
/// See `std::fmt` for more information.
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`.
7876
///
7977
/// # Examples
8078
///
@@ -85,8 +83,7 @@ macro_rules! print {
8583
#[macro_export]
8684
#[stable(feature = "rust1", since = "1.0.0")]
8785
macro_rules! println {
88-
($fmt:expr) => (print!(concat!($fmt, "\n")));
89-
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
86+
($($arg:tt)*) => ($crate::old_io::stdio::println_args(format_args!($($arg)*)))
9087
}
9188

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

trunk/src/libstd/net/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
//! Networking primitives for TCP/UDP communication
1212
//!
1313
//! > **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.
14+
//! > development.
1615
1716
#![unstable(feature = "net")]
1817

trunk/src/libstd/old_io/stdio.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,18 @@ 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+
}
538552
}

trunk/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::prelude::*;
213+
use os::unix::*;
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::prelude::*;
241+
use os::unix::*;
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::prelude::*;
1708+
use os::unix::AsRawFd;
17091709
file.as_raw_fd()
17101710
}
17111711

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

trunk/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, for example, `a/./b`, `a/b/`,
90-
//! `/a/b/.` and `a/b` all have components `a` and `b`, but `./a/b`
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`
9191
//! has a leading current directory component.
9292
//!
9393
//! No other normalization takes place by default. In particular,

trunk/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::process::ExitStatusExt;
576+
use os::unix::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::prelude::*;
636+
use os::unix::*;
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::prelude::*;
649+
use os::unix::*;
650650
use libc;
651651

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

trunk/src/libstd/sys/unix/backtrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn write(w: &mut Write) -> io::Result<()> {
118118
// local, it still displays much nicer backtraces when a
119119
// couple of tasks panic simultaneously
120120
static LOCK: StaticMutex = MUTEX_INIT;
121-
let _g = LOCK.lock();
121+
let _g = unsafe { LOCK.lock() };
122122

123123
try!(writeln!(w, "stack backtrace:"));
124124
// 100 lines should be enough

0 commit comments

Comments
 (0)