about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-01 09:18:19 -0700
committerGitHub <noreply@github.com>2021-10-01 09:18:19 -0700
commitd388428aaad3915c65106a1aae2d09effcdbc034 (patch)
tree3288270fef85c00c7d03864229fc69f4a676ec4d /compiler/rustc_codegen_llvm/src
parent2f67063fbe7ab6bc0793046ecb2c0626531ad451 (diff)
parent6490ed30e1025fbb85b3a2dd4849a249c072fb30 (diff)
downloadrust-d388428aaad3915c65106a1aae2d09effcdbc034.tar.gz
rust-d388428aaad3915c65106a1aae2d09effcdbc034.zip
Rollup merge of #89340 - FabianWolff:issue-89173, r=petrochenkov
Improve error message for `printf`-style format strings

Fixes #89173. The following is actually supported today:
```rust
fn main() {
    let num = 5;
    let width = 20;
    print!("%*2$x", num, width);
}
```
```
error: multiple unused formatting arguments
 --> src/main.rs:4:21
  |
4 |     print!("%*2$x", num, width);
  |            -------  ^^^  ^^^^^ argument never used
  |            ||       |
  |            ||       argument never used
  |            |help: format specifiers use curly braces: `{:1$x}`
  |            multiple missing formatting specifiers
  |
  = note: printf formatting not supported; see the documentation for `std::fmt`
```
However, as noted in #89173, something like
```rust
    print!("%0*x", width, num);
```
does not give a helpful suggestion. I think this is partly intended, because there actually _is_ no Rust equivalent to this; you always have to use a positional or named argument to specify the width (instead of just using the "next" argument, as `printf` or even `.*` as a precision specifier in Rust would). Therefore, I have added a note:
```
[...]
note: format specifiers use curly braces, and you have to use a positional or named parameter for the width
 --> t2.rs:4:13
  |
4 |     print!("%0*x", width, num);
  |             ^^^^
  = note: printf formatting not supported; see the documentation for `std::fmt`
```
This is not perfect, but it should at least point the user in the right direction, instead of issuing no explanation at all.

cc ```@lcnr```
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions