diff options
| author | bors <bors@rust-lang.org> | 2015-03-13 20:22:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-13 20:22:16 +0000 |
| commit | 3e4be02b80a3dd27bce20870958fe0aef7e7336d (patch) | |
| tree | 156b54e84eeb1df2818be29b53ab7f35b5bc80f0 /src/libsyntax | |
| parent | 9eb69abad8ffbce840e7dc7038ddea434dc987f1 (diff) | |
| parent | 981bf5f690d1d7c5cf3e1419ac7a7c86dbc7a4d5 (diff) | |
| download | rust-3e4be02b80a3dd27bce20870958fe0aef7e7336d.tar.gz rust-3e4be02b80a3dd27bce20870958fe0aef7e7336d.zip | |
Auto merge of #23292 - alexcrichton:stabilize-io, r=aturon
The new `std::io` module has had some time to bake now, and this commit
stabilizes its functionality. There are still portions of the module which
remain unstable, and below contains a summart of the actions taken.
This commit also deprecates the entire contents of the `old_io` module in a
blanket fashion. All APIs should now have a reasonable replacement in the
new I/O modules.
Stable APIs:
* `std::io` (the name)
* `std::io::prelude` (the name)
* `Read`
* `Read::read`
* `Read::{read_to_end, read_to_string}` after being modified to return a `usize`
for the number of bytes read.
* `ReadExt`
* `Write`
* `Write::write`
* `Write::{write_all, write_fmt}`
* `WriteExt`
* `BufRead`
* `BufRead::{fill_buf, consume}`
* `BufRead::{read_line, read_until}` after being modified to return a `usize`
for the number of bytes read.
* `BufReadExt`
* `BufReader`
* `BufReader::{new, with_capacity}`
* `BufReader::{get_ref, get_mut, into_inner}`
* `{Read,BufRead} for BufReader`
* `BufWriter`
* `BufWriter::{new, with_capacity}`
* `BufWriter::{get_ref, get_mut, into_inner}`
* `Write for BufWriter`
* `IntoInnerError`
* `IntoInnerError::{error, into_inner}`
* `{Error,Display} for IntoInnerError`
* `LineWriter`
* `LineWriter::{new, with_capacity}` - `with_capacity` was added
* `LineWriter::{get_ref, get_mut, into_inner}` - `get_mut` was added)
* `Write for LineWriter`
* `BufStream`
* `BufStream::{new, with_capacities}`
* `BufStream::{get_ref, get_mut, into_inner}`
* `{BufRead,Read,Write} for BufStream`
* `stdin`
* `Stdin`
* `Stdin::lock`
* `Stdin::read_line` - added method
* `StdinLock`
* `Read for Stdin`
* `{Read,BufRead} for StdinLock`
* `stdout`
* `Stdout`
* `Stdout::lock`
* `StdoutLock`
* `Write for Stdout`
* `Write for StdoutLock`
* `stderr`
* `Stderr`
* `Stderr::lock`
* `StderrLock`
* `Write for Stderr`
* `Write for StderrLock`
* `io::Result`
* `io::Error`
* `io::Error::last_os_error`
* `{Display, Error} for Error`
Unstable APIs:
(reasons can be found in the commit itself)
* `Write::flush`
* `Seek`
* `ErrorKind`
* `Error::new`
* `Error::from_os_error`
* `Error::kind`
Deprecated APIs
* `Error::description` - available via the `Error` trait
* `Error::detail` - available via the `Display` implementation
* `thread::Builder::{stdout, stderr}`
Changes in functionality:
* `old_io::stdio::set_stderr` is now a noop as the infrastructure for printing
backtraces has migrated to `std::io`.
[breaking-change]
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 72 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 4 |
3 files changed, 50 insertions, 27 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index e094cbcac53..32857769acf 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -19,10 +19,11 @@ use diagnostics; use std::cell::{RefCell, Cell}; use std::fmt; -use std::old_io; -use std::string::String; +use std::io::prelude::*; +use std::io; use term::WriterWrapper; use term; +use libc; /// maximum number of lines we will print for each error; arbitrary. const MAX_LINES: usize = 6; @@ -271,7 +272,7 @@ impl Level { fn print_maybe_styled(w: &mut EmitterWriter, msg: &str, - color: term::attr::Attr) -> old_io::IoResult<()> { + color: term::attr::Attr) -> io::Result<()> { match w.dst { Terminal(ref mut t) => { try!(t.attr(color)); @@ -289,23 +290,21 @@ fn print_maybe_styled(w: &mut EmitterWriter, // to be miscolored. We assume this is rare enough that we don't // have to worry about it. if msg.ends_with("\n") { - try!(t.write_str(&msg[..msg.len()-1])); + try!(t.write_all(msg[..msg.len()-1].as_bytes())); try!(t.reset()); - try!(t.write_str("\n")); + try!(t.write_all(b"\n")); } else { - try!(t.write_str(msg)); + try!(t.write_all(msg.as_bytes())); try!(t.reset()); } Ok(()) } - Raw(ref mut w) => { - w.write_str(msg) - } + Raw(ref mut w) => w.write_all(msg.as_bytes()), } } fn print_diagnostic(dst: &mut EmitterWriter, topic: &str, lvl: Level, - msg: &str, code: Option<&str>) -> old_io::IoResult<()> { + msg: &str, code: Option<&str>) -> io::Result<()> { if !topic.is_empty() { try!(write!(&mut dst.dst, "{} ", topic)); } @@ -324,7 +323,7 @@ fn print_diagnostic(dst: &mut EmitterWriter, topic: &str, lvl: Level, } None => () } - try!(dst.dst.write_char('\n')); + try!(write!(&mut dst.dst, "\n")); Ok(()) } @@ -335,18 +334,18 @@ pub struct EmitterWriter { enum Destination { Terminal(Box<term::Terminal<WriterWrapper> + Send>), - Raw(Box<Writer + Send>), + Raw(Box<Write + Send>), } impl EmitterWriter { pub fn stderr(color_config: ColorConfig, registry: Option<diagnostics::registry::Registry>) -> EmitterWriter { - let stderr = old_io::stderr(); + let stderr = io::stderr(); let use_color = match color_config { Always => true, Never => false, - Auto => stderr.get_ref().isatty() + Auto => stderr_isatty(), }; if use_color { @@ -360,17 +359,42 @@ impl EmitterWriter { } } - pub fn new(dst: Box<Writer + Send>, + pub fn new(dst: Box<Write + Send>, registry: Option<diagnostics::registry::Registry>) -> EmitterWriter { EmitterWriter { dst: Raw(dst), registry: registry } } } -impl Writer for Destination { - fn write_all(&mut self, bytes: &[u8]) -> old_io::IoResult<()> { +#[cfg(unix)] +fn stderr_isatty() -> bool { + unsafe { libc::isatty(libc::STDERR_FILENO) != 0 } +} +#[cfg(windows)] +fn stderr_isatty() -> bool { + const STD_ERROR_HANDLE: libc::DWORD = -12; + extern "system" { + fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; + fn GetConsoleMode(hConsoleHandle: libc::HANDLE, + lpMode: libc::LPDWORD) -> libc::BOOL; + } + unsafe { + let handle = GetStdHandle(STD_ERROR_HANDLE); + let mut out = 0; + GetConsoleMode(handle, &mut out) != 0 + } +} + +impl Write for Destination { + fn write(&mut self, bytes: &[u8]) -> io::Result<usize> { + match *self { + Terminal(ref mut t) => t.write(bytes), + Raw(ref mut w) => w.write(bytes), + } + } + fn flush(&mut self) -> io::Result<()> { match *self { - Terminal(ref mut t) => t.write_all(bytes), - Raw(ref mut w) => w.write_all(bytes), + Terminal(ref mut t) => t.flush(), + Raw(ref mut w) => w.flush(), } } } @@ -403,7 +427,7 @@ impl Emitter for EmitterWriter { } fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan, - msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> old_io::IoResult<()> { + msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::Result<()> { let sp = rsp.span(); // We cannot check equality directly with COMMAND_LINE_SP @@ -451,7 +475,7 @@ fn highlight_lines(err: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span, lvl: Level, - lines: codemap::FileLines) -> old_io::IoResult<()> { + lines: codemap::FileLines) -> io::Result<()> { let fm = &*lines.file; let mut elided = false; @@ -560,7 +584,7 @@ fn custom_highlight_lines(w: &mut EmitterWriter, sp: Span, lvl: Level, lines: codemap::FileLines) - -> old_io::IoResult<()> { + -> io::Result<()> { let fm = &*lines.file; let lines = &lines.lines[..]; @@ -617,8 +641,8 @@ fn custom_highlight_lines(w: &mut EmitterWriter, fn print_macro_backtrace(w: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span) - -> old_io::IoResult<()> { - let cs = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> old_io::IoResult<_> { + -> io::Result<()> { + let cs = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> io::Result<_> { match expn_info { Some(ei) => { let ss = ei.callee.span.map_or(String::new(), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 90f0dc30c75..f60ac8f3f33 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -30,7 +30,6 @@ #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(old_io)] #![feature(libc)] #![feature(old_path)] #![feature(quote, unsafe_destructor)] diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index f5781e0587d..d9887c28e5c 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1470,11 +1470,11 @@ mod test { use diagnostic; use parse::token; use parse::token::{str_to_ident}; - use std::old_io::util; + use std::io; fn mk_sh() -> diagnostic::SpanHandler { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. - let emitter = diagnostic::EmitterWriter::new(Box::new(util::NullWriter), None); + let emitter = diagnostic::EmitterWriter::new(Box::new(io::sink()), None); let handler = diagnostic::mk_handler(true, Box::new(emitter)); diagnostic::mk_span_handler(handler, CodeMap::new()) } |
