]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #63121 - estebank:formatting-pos, r=alexcrichton
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 2 Aug 2019 22:09:06 +0000 (00:09 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2019 22:09:06 +0000 (00:09 +0200)
commitedc846f29eac8a45555f19a9fd951ed414398776
tree0be1fc6ac0861dd9dcb59c83e9327e7b657c20ac
parenta2735a3e0dd58e4b41b933731928678b7a2da700
parent22ea38dd792ec9983084a101ca6159999a9b851a
Rollup merge of #63121 - estebank:formatting-pos, r=alexcrichton

On `format!()` arg count mismatch provide extra info

When positional width and precision formatting flags are present in a
formatting string that has an argument count mismatch, provide extra
information pointing at them making it easiser to understand where the
problem may lay:

```
error: 4 positional arguments in format string, but there are 3 arguments
  --> $DIR/ifmt-bad-arg.rs:78:15
   |
LL |     println!("{} {:.*} {}", 1, 3.2, 4);
   |               ^^ ^^--^ ^^      --- this parameter corresponds to the precision flag
   |                    |
   |                    this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
   |
   = note: positional arguments are zero-based
   = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html

error: 4 positional arguments in format string, but there are 3 arguments
  --> $DIR/ifmt-bad-arg.rs:81:15
   |
LL |     println!("{} {:07$.*} {}", 1, 3.2, 4);
   |               ^^ ^^-----^ ^^      --- this parameter corresponds to the precision flag
   |                    |  |
   |                    |  this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
   |                    this width flag expects an `usize` argument at position 7, but there are 3 arguments
   |
   = note: positional arguments are zero-based
   = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html

error: invalid reference to positional argument 7 (there are 3 arguments)
  --> $DIR/ifmt-bad-arg.rs:84:18
   |
LL |     println!("{} {:07$} {}", 1, 3.2, 4);
   |                  ^^^--^
   |                     |
   |                     this width flag expects an `usize` argument at position 7, but there are 3 arguments
   |
   = note: positional arguments are zero-based
   = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
```

Fix #49384.
src/libfmt_macros/lib.rs
src/libsyntax_pos/lib.rs