diff options
| author | James Dietz <jamesthespeedy@gmail.com> | 2023-03-14 18:01:14 -0400 |
|---|---|---|
| committer | James Dietz <jamesthespeedy@gmail.com> | 2023-03-27 21:01:23 -0400 |
| commit | ff88787ff0238ed5b5d70317e93b95b32bbde4c9 (patch) | |
| tree | 272aaca0b129f04af3b5f2f440f85134b1fadbcc /tests/ui/macros | |
| parent | 2036fdd24f77d607dcfaa24c48fbe85d3f785823 (diff) | |
| download | rust-ff88787ff0238ed5b5d70317e93b95b32bbde4c9.tar.gz rust-ff88787ff0238ed5b5d70317e93b95b32bbde4c9.zip | |
check for write macro and write_fmt with err msg
added ui test blessed stderrs fixed typo reblessed
Diffstat (limited to 'tests/ui/macros')
| -rw-r--r-- | tests/ui/macros/missing-writer.rs | 17 | ||||
| -rw-r--r-- | tests/ui/macros/missing-writer.stderr | 59 |
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/ui/macros/missing-writer.rs b/tests/ui/macros/missing-writer.rs new file mode 100644 index 00000000000..7df965c3684 --- /dev/null +++ b/tests/ui/macros/missing-writer.rs @@ -0,0 +1,17 @@ +// Check error for missing writer in writeln! and write! macro +fn main() { + let x = 1; + let y = 2; + write!("{}_{}", x, y); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with + //~| ERROR cannot write into `&'static str` + //~| NOTE must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method + //~| HELP a writer is needed before this format string + writeln!("{}_{}", x, y); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with + //~| ERROR cannot write into `&'static str` + //~| NOTE must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method + //~| HELP a writer is needed before this format string +} diff --git a/tests/ui/macros/missing-writer.stderr b/tests/ui/macros/missing-writer.stderr new file mode 100644 index 00000000000..86dfe7d65ea --- /dev/null +++ b/tests/ui/macros/missing-writer.stderr @@ -0,0 +1,59 @@ +error: format argument must be a string literal + --> $DIR/missing-writer.rs:5:21 + | +LL | write!("{}_{}", x, y); + | ^ + | +help: you might be missing a string literal to format with + | +LL | write!("{}_{}", "{} {}", x, y); + | ++++++++ + +error: format argument must be a string literal + --> $DIR/missing-writer.rs:11:23 + | +LL | writeln!("{}_{}", x, y); + | ^ + | +help: you might be missing a string literal to format with + | +LL | writeln!("{}_{}", "{} {}", x, y); + | ++++++++ + +error[E0599]: cannot write into `&'static str` + --> $DIR/missing-writer.rs:5:12 + | +LL | write!("{}_{}", x, y); + | -------^^^^^^^------- method not found in `&str` + | +note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method + --> $DIR/missing-writer.rs:5:12 + | +LL | write!("{}_{}", x, y); + | ^^^^^^^ +help: a writer is needed before this format string + --> $DIR/missing-writer.rs:5:12 + | +LL | write!("{}_{}", x, y); + | ^ + +error[E0599]: cannot write into `&'static str` + --> $DIR/missing-writer.rs:11:14 + | +LL | writeln!("{}_{}", x, y); + | ---------^^^^^^^------- method not found in `&str` + | +note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method + --> $DIR/missing-writer.rs:11:14 + | +LL | writeln!("{}_{}", x, y); + | ^^^^^^^ +help: a writer is needed before this format string + --> $DIR/missing-writer.rs:11:14 + | +LL | writeln!("{}_{}", x, y); + | ^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0599`. |
