Improve error message for printf-style format strings
This commit is contained in:
parent
1d71ba8623
commit
6490ed30e1
6 changed files with 105 additions and 26 deletions
14
src/test/ui/fmt/issue-89173.rs
Normal file
14
src/test/ui/fmt/issue-89173.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Regression test for #89173: Make sure a helpful note is issued for
|
||||
// printf-style format strings using `*` to specify the width.
|
||||
|
||||
fn main() {
|
||||
let num = 0x0abcde;
|
||||
let width = 6;
|
||||
print!("%0*x", width, num);
|
||||
//~^ ERROR: multiple unused formatting arguments
|
||||
//~| NOTE: multiple missing formatting specifiers
|
||||
//~| NOTE: argument never used
|
||||
//~| NOTE: argument never used
|
||||
//~| NOTE: format specifiers use curly braces, and you have to use a positional or named parameter for the width
|
||||
//~| NOTE: printf formatting not supported
|
||||
}
|
||||
18
src/test/ui/fmt/issue-89173.stderr
Normal file
18
src/test/ui/fmt/issue-89173.stderr
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
error: multiple unused formatting arguments
|
||||
--> $DIR/issue-89173.rs:7:20
|
||||
|
|
||||
LL | print!("%0*x", width, num);
|
||||
| ------ ^^^^^ ^^^ argument never used
|
||||
| | |
|
||||
| | argument never used
|
||||
| multiple missing formatting specifiers
|
||||
|
|
||||
note: format specifiers use curly braces, and you have to use a positional or named parameter for the width
|
||||
--> $DIR/issue-89173.rs:7:13
|
||||
|
|
||||
LL | print!("%0*x", width, num);
|
||||
| ^^^^
|
||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue