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
|
|
@ -28,25 +28,19 @@ LL | println!("{}", FOO);
|
|||
| ^^^ referenced constant has errors
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/conditional_array_execution.rs:19:5
|
||||
--> $DIR/conditional_array_execution.rs:19:14
|
||||
|
|
||||
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||
| ----- attempt to subtract with overflow
|
||||
...
|
||||
LL | println!("{}", FOO);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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[E0080]: erroneous constant used
|
||||
--> $DIR/conditional_array_execution.rs:19:5
|
||||
--> $DIR/conditional_array_execution.rs:19:14
|
||||
|
|
||||
LL | println!("{}", FOO);
|
||||
| ^^^^^^^^^^^^^^^---^^
|
||||
| |
|
||||
| referenced constant has errors
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
| ^^^^ --- referenced constant has errors
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/conditional_array_execution.rs:19:20
|
||||
|
|
|
|||
|
|
@ -51,25 +51,19 @@ LL | println!("{} {}", X, Y);
|
|||
| ^ referenced constant has errors
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/issue-43197.rs:24:5
|
||||
--> $DIR/issue-43197.rs:24:14
|
||||
|
|
||||
LL | const X: u32 = 0-1;
|
||||
| --- attempt to subtract with overflow
|
||||
...
|
||||
LL | println!("{} {}", X, Y);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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[E0080]: erroneous constant used
|
||||
--> $DIR/issue-43197.rs:24:5
|
||||
--> $DIR/issue-43197.rs:24:14
|
||||
|
|
||||
LL | println!("{} {}", X, Y);
|
||||
| ^^^^^^^^^^^^^^^^^^-^^^^^
|
||||
| |
|
||||
| referenced constant has errors
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
| ^^^^^^^ - referenced constant has errors
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/issue-43197.rs:24:26
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/issue-44578.rs:35:5
|
||||
--> $DIR/issue-44578.rs:35:14
|
||||
|
|
||||
LL | const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
|
||||
| ------------------------------------ index out of bounds: the len is 1 but the index is 1
|
||||
...
|
||||
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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[E0080]: erroneous constant used
|
||||
--> $DIR/issue-44578.rs:35:5
|
||||
--> $DIR/issue-44578.rs:35:14
|
||||
|
|
||||
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
||||
| ^^^^^^^^^^^^^^^--------------------------^^
|
||||
| |
|
||||
| referenced constant has errors
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
| ^^^^ -------------------------- referenced constant has errors
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/issue-44578.rs:35:20
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@
|
|||
|
||||
fn main() {
|
||||
println!("{");
|
||||
//~^ ERROR invalid format string: expected `'}'` but string was terminated
|
||||
println!("{{}}");
|
||||
println!("}");
|
||||
//~^ ERROR invalid format string: unmatched `}` found
|
||||
let _ = format!("{_foo}", _foo = 6usize);
|
||||
//~^ ERROR invalid format string: invalid argument name `_foo`
|
||||
let _ = format!("{_}", _ = 6usize);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,5 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
println!(3 + 4); //~ ERROR expected a literal
|
||||
println!(3 + 4);
|
||||
//~^ ERROR format argument must be a string literal
|
||||
println!(3, 4);
|
||||
//~^ ERROR format argument must be a string literal
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,22 @@
|
|||
error: expected a literal
|
||||
error: format argument must be a string literal
|
||||
--> $DIR/bad_hello.rs:12:14
|
||||
|
|
||||
LL | println!(3 + 4); //~ ERROR expected a literal
|
||||
LL | println!(3 + 4);
|
||||
| ^^^^^
|
||||
help: you might be missing a string literal to format with
|
||||
|
|
||||
LL | println!("{}", 3 + 4); //~ ERROR expected a literal
|
||||
| ^^^^^^^^^^^
|
||||
LL | println!("{}", 3 + 4);
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: format argument must be a string literal
|
||||
--> $DIR/bad_hello.rs:14:14
|
||||
|
|
||||
LL | println!(3, 4);
|
||||
| ^
|
||||
help: you might be missing a string literal to format with
|
||||
|
|
||||
LL | println!("{}, {}", 3, 4);
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ error: multiple unused formatting arguments
|
|||
--> $DIR/format-foreign.rs:12:30
|
||||
|
|
||||
LL | println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
|
||||
| -------------------------^^^^^^^^--^^^^^^^--^-- multiple unused arguments in this statement
|
||||
| -------------- ^^^^^^^^ ^^^^^^^ ^
|
||||
| |
|
||||
| multiple missing formatting arguments
|
||||
|
|
||||
= help: `%.*3$s` should be written as `{:.2$}`
|
||||
= help: `%s` should be written as `{}`
|
||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||
= 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: argument never used
|
||||
--> $DIR/format-foreign.rs:13:29
|
||||
|
|
|
|||
|
|
@ -2,24 +2,21 @@ error: multiple unused formatting arguments
|
|||
--> $DIR/format-unused-lables.rs:12:22
|
||||
|
|
||||
LL | println!("Test", 123, 456, 789);
|
||||
| -----------------^^^--^^^--^^^-- multiple unused arguments in this statement
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
| ------ ^^^ ^^^ ^^^
|
||||
| |
|
||||
| multiple missing formatting arguments
|
||||
|
||||
error: multiple unused formatting arguments
|
||||
--> $DIR/format-unused-lables.rs:16:9
|
||||
|
|
||||
LL | / println!("Test2",
|
||||
LL | | 123, //~ ERROR multiple unused formatting arguments
|
||||
| | ^^^
|
||||
LL | | 456,
|
||||
| | ^^^
|
||||
LL | | 789
|
||||
| | ^^^
|
||||
LL | | );
|
||||
| |______- multiple unused arguments in this statement
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
LL | println!("Test2",
|
||||
| ------- multiple missing formatting arguments
|
||||
LL | 123, //~ ERROR multiple unused formatting arguments
|
||||
| ^^^
|
||||
LL | 456,
|
||||
| ^^^
|
||||
LL | 789
|
||||
| ^^^
|
||||
|
||||
error: named argument never used
|
||||
--> $DIR/format-unused-lables.rs:21:35
|
||||
|
|
@ -30,18 +27,18 @@ LL | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never u
|
|||
error: multiple unused formatting arguments
|
||||
--> $DIR/format-unused-lables.rs:24:9
|
||||
|
|
||||
LL | / println!("Some more $STUFF",
|
||||
LL | | "woo!", //~ ERROR multiple unused formatting arguments
|
||||
| | ^^^^^^
|
||||
LL | | STUFF=
|
||||
LL | | "things"
|
||||
| | ^^^^^^^^
|
||||
LL | | , UNUSED="args");
|
||||
| |_______________________^^^^^^_- multiple unused arguments in this statement
|
||||
LL | println!("Some more $STUFF",
|
||||
| ------------------ multiple missing formatting arguments
|
||||
LL | "woo!", //~ ERROR multiple unused formatting arguments
|
||||
| ^^^^^^
|
||||
LL | STUFF=
|
||||
LL | "things"
|
||||
| ^^^^^^^^
|
||||
LL | , UNUSED="args");
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: `$STUFF` should be written as `{STUFF}`
|
||||
= note: shell formatting not supported; see the documentation for `std::fmt`
|
||||
= 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: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ LL | println!("Hello, World!");
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expanding `println! { "Hello, World!" }`
|
||||
= note: to `print ! ( concat ! ( "Hello, World!" , "/n" ) )`
|
||||
= note: expanding `print! { concat ! ( "Hello, World!" , "/n" ) }`
|
||||
= note: to `$crate :: io :: _print ( format_args ! ( concat ! ( "Hello, World!" , "/n" ) )
|
||||
)`
|
||||
= note: to `{ print ! ( "Hello, World!" ) ; print ! ( "/n" ) ; }`
|
||||
= note: expanding `print! { "Hello, World!" }`
|
||||
= note: to `$crate :: io :: _print ( format_args ! ( "Hello, World!" ) )`
|
||||
= note: expanding `print! { "/n" }`
|
||||
= note: to `$crate :: io :: _print ( format_args ! ( "/n" ) )`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue