-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add eprint!
and eprintln!
macros to the prelude.
#39229
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,9 @@ macro_rules! panic { | |
/// necessary to use `io::stdout().flush()` to ensure the output is emitted | ||
/// immediately. | ||
/// | ||
/// Use `print!` only for the primary output of your program. Use | ||
/// `eprint!` instead to print error and progress messages. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if writing to `io::stdout()` fails. | ||
|
@@ -105,6 +108,9 @@ macro_rules! print { | |
/// Use the `format!` syntax to write data to the standard output. | ||
/// See `std::fmt` for more information. | ||
/// | ||
/// Use `println!` only for the primary output of your program. Use | ||
/// `eprintln!` instead to print error and progress messages. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if writing to `io::stdout()` fails. | ||
|
@@ -124,6 +130,45 @@ macro_rules! println { | |
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); | ||
} | ||
|
||
/// Macro for printing to the standard error. | ||
/// | ||
/// Equivalent to the `print!` macro, except that output goes to | ||
/// `io::stderr()` instead of `io::stdout()`. See `print!` for | ||
/// example usage. | ||
/// | ||
/// Use `eprint!` only for error and progress messages. Use `print!` | ||
/// instead for the primary output of your program. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if writing to `io::stderr()` fails. | ||
#[macro_export] | ||
#[unstable(feature = "eprint", issue="39228")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue #40528 |
||
#[allow_internal_unstable] | ||
macro_rules! eprint { | ||
($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*))); | ||
} | ||
|
||
/// Macro for printing to the standard error, with a newline. | ||
/// | ||
/// Equivalent to the `println!` macro, except that output goes to | ||
/// `io::stderr()` instead of `io::stdout()`. See `println!` for | ||
/// example usage. | ||
/// | ||
/// Use `eprintln!` only for error and progress messages. Use `println!` | ||
/// instead for the primary output of your program. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if writing to `io::stderr()` fails. | ||
#[macro_export] | ||
#[unstable(feature = "eprint", issue="39228")] | ||
macro_rules! eprintln { | ||
() => (eprint!("\n")); | ||
($fmt:expr) => (eprint!(concat!($fmt, "\n"))); | ||
($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*)); | ||
} | ||
|
||
/// A macro to select an event from a number of receivers. | ||
/// | ||
/// This macro is used to wait for the first event to occur on a number of | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(eprint)] | ||
|
||
use std::{env, process}; | ||
|
||
fn child() { | ||
print!("[stdout 0]"); | ||
print!("[stdout {}]", 1); | ||
println!("[stdout {}]", 2); | ||
println!(); | ||
eprint!("[stderr 0]"); | ||
eprint!("[stderr {}]", 1); | ||
eprintln!("[stderr {}]", 2); | ||
eprintln!(); | ||
} | ||
|
||
fn parent() { | ||
let this = env::args().next().unwrap(); | ||
let output = process::Command::new(this).arg("-").output().unwrap(); | ||
assert!(output.status.success()); | ||
|
||
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
let stderr = String::from_utf8(output.stderr).unwrap(); | ||
|
||
assert_eq!(stdout, "[stdout 0][stdout 1][stdout 2]\n\n"); | ||
assert_eq!(stderr, "[stderr 0][stderr 1][stderr 2]\n\n"); | ||
} | ||
|
||
fn main() { | ||
if env::args().count() == 2 { child() } else { parent() } | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to merge this with
_print()
?