]> git.lizzy.rs Git - rust.git/commit
Generate correct suggestion with named arguments used positionally
authorPreston From <prestonfrom@gmail.com>
Sat, 16 Jul 2022 21:13:14 +0000 (15:13 -0600)
committerPreston From <prestonfrom@gmail.com>
Mon, 25 Jul 2022 06:00:27 +0000 (00:00 -0600)
commit3330c7d1c3bcfd2c452b794db66705b92fb54a3c
tree54a0678eba5caf07335b5a1ede0314f515bde6f8
parent530c0a81d50c6e1c9b1bdee0970d27af02ca49be
Generate correct suggestion with named arguments used positionally

Address issue #99265 by checking each positionally used argument
to see if the argument is named and adding a lint to use the name
instead. This way, when named arguments are used positionally in a
different order than their argument order, the suggested lint is
correct.

For example:
```
println!("{b} {}", a=1, b=2);
```
This will now generate the suggestion:
```
println!("{b} {a}", a=1, b=2);
```

Additionally, this check now also correctly replaces or inserts
only where the positional argument is (or would be if implicit).
Also, width and precision are replaced with their argument names
when they exists.

Since the issues were so closely related, this fix for issue #99265
also fixes issue #99266.

Fixes #99265
Fixes #99266
12 files changed:
compiler/rustc_builtin_macros/src/asm.rs
compiler/rustc_builtin_macros/src/format.rs
compiler/rustc_lint/src/context.rs
compiler/rustc_lint_defs/src/lib.rs
compiler/rustc_parse_format/src/lib.rs
compiler/rustc_parse_format/src/tests.rs
compiler/rustc_trait_selection/src/traits/on_unimplemented.rs
src/test/ui/macros/issue-98466.stderr
src/test/ui/macros/issue-99265.fixed [new file with mode: 0644]
src/test/ui/macros/issue-99265.rs [new file with mode: 0644]
src/test/ui/macros/issue-99265.stderr [new file with mode: 0644]
src/tools/clippy/clippy_lints/src/write.rs