Improve suggestion for missing fmt str in println
Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal.
This commit is contained in:
parent
bc14d71622
commit
f53c145ef1
14 changed files with 122 additions and 102 deletions
|
@ -1,23 +1,21 @@
|
|||
error: invalid format string: expected `'}'` but string was terminated
|
||||
--> $DIR/format-string-error.rs:12:5
|
||||
--> $DIR/format-string-error.rs:12:16
|
||||
|
|
||||
LL | println!("{");
|
||||
| ^^^^^^^^^^^^^^ expected `'}'` in format string
|
||||
| ^ expected `'}'` in format string
|
||||
|
|
||||
= note: if you intended to print `{`, you can escape it using `{{`
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: invalid format string: unmatched `}` found
|
||||
--> $DIR/format-string-error.rs:14:5
|
||||
--> $DIR/format-string-error.rs:15:15
|
||||
|
|
||||
LL | println!("}");
|
||||
| ^^^^^^^^^^^^^^ unmatched `}` in format string
|
||||
| ^ unmatched `}` in format string
|
||||
|
|
||||
= note: if you intended to print `}`, you can escape it using `}}`
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: invalid format string: invalid argument name `_foo`
|
||||
--> $DIR/format-string-error.rs:15:23
|
||||
--> $DIR/format-string-error.rs:17:23
|
||||
|
|
||||
LL | let _ = format!("{_foo}", _foo = 6usize);
|
||||
| ^^^^ invalid argument name in format string
|
||||
|
@ -25,7 +23,7 @@ LL | let _ = format!("{_foo}", _foo = 6usize);
|
|||
= note: argument names cannot start with an underscore
|
||||
|
||||
error: invalid format string: invalid argument name `_`
|
||||
--> $DIR/format-string-error.rs:17:23
|
||||
--> $DIR/format-string-error.rs:19:23
|
||||
|
|
||||
LL | let _ = format!("{_}", _ = 6usize);
|
||||
| ^ invalid argument name in format string
|
||||
|
@ -33,7 +31,7 @@ LL | let _ = format!("{_}", _ = 6usize);
|
|||
= note: argument names cannot start with an underscore
|
||||
|
||||
error: invalid format string: expected `'}'` but string was terminated
|
||||
--> $DIR/format-string-error.rs:19:23
|
||||
--> $DIR/format-string-error.rs:21:23
|
||||
|
|
||||
LL | let _ = format!("{");
|
||||
| ^ expected `'}'` in format string
|
||||
|
@ -41,7 +39,7 @@ LL | let _ = format!("{");
|
|||
= note: if you intended to print `{`, you can escape it using `{{`
|
||||
|
||||
error: invalid format string: unmatched `}` found
|
||||
--> $DIR/format-string-error.rs:21:22
|
||||
--> $DIR/format-string-error.rs:23:22
|
||||
|
|
||||
LL | let _ = format!("}");
|
||||
| ^ unmatched `}` in format string
|
||||
|
@ -49,7 +47,7 @@ LL | let _ = format!("}");
|
|||
= note: if you intended to print `}`, you can escape it using `}}`
|
||||
|
||||
error: invalid format string: expected `'}'`, found `'/'`
|
||||
--> $DIR/format-string-error.rs:23:23
|
||||
--> $DIR/format-string-error.rs:25:23
|
||||
|
|
||||
LL | let _ = format!("{/}");
|
||||
| ^ expected `}` in format string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue