mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Improve write! and writeln! error when called without destination
This commit is contained in:
@@ -611,6 +611,9 @@ macro_rules! write {
|
||||
($dst:expr, $($arg:tt)*) => {
|
||||
$dst.write_fmt($crate::format_args!($($arg)*))
|
||||
};
|
||||
($($arg:tt)*) => {
|
||||
compile_error!("requires a destination and format arguments, like `write!(dest, \"format string\", args...)`")
|
||||
};
|
||||
}
|
||||
|
||||
/// Writes formatted data into a buffer, with a newline appended.
|
||||
@@ -649,6 +652,9 @@ macro_rules! writeln {
|
||||
($dst:expr, $($arg:tt)*) => {
|
||||
$dst.write_fmt($crate::format_args_nl!($($arg)*))
|
||||
};
|
||||
($($arg:tt)*) => {
|
||||
compile_error!("requires a destination and format arguments, like `writeln!(dest, \"format string\", args...)`")
|
||||
};
|
||||
}
|
||||
|
||||
/// Indicates unreachable code.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Check that `write!` without a destination gives a helpful error message.
|
||||
// See https://github.com/rust-lang/rust/issues/152493
|
||||
|
||||
fn main() {
|
||||
write!("S");
|
||||
//~^ ERROR requires a destination and format arguments
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
error: requires a destination and format arguments, like `write!(dest, "format string", args...)`
|
||||
--> $DIR/write-missing-destination.rs:5:5
|
||||
|
|
||||
LL | write!("S");
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
Reference in New Issue
Block a user