Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo clippy --fix broken for positional arguments #10128

Closed
scontain opened this issue Dec 29, 2022 · 1 comment · Fixed by #11576
Closed

cargo clippy --fix broken for positional arguments #10128

scontain opened this issue Dec 29, 2022 · 1 comment · Fixed by #11576
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@scontain
Copy link

I applied cargo clippy --fix --allow-dirty to

fn main() {

    println!(
        "\nI doing {2} from {1} years and i {0} it",
        "like", 20, "programming"
    );

}

I expected to see this happen: explanation

Instead, this happened: explanation

warning: failed to automatically apply fixes suggested by rustc to crate `ca_p1`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: invalid reference to positional argument 1 (there is 1 argument)
 --> src/main.rs:5:38
  |
5 |         "\nI doing programming from {1} years and i like it", 20
  |                                      ^
  |
  = note: positional arguments are zero-based

error: argument never used
 --> src/main.rs:5:63
  |
5 |         "\nI doing programming from {1} years and i like it", 20
  |         ----------------------------------------------------  ^^ argument never used
  |         |
  |         formatting specifier missing

error: aborting due to 2 previous errors

Original diagnostics will follow.

warning: literal with an empty format string
 --> src/main.rs:6:21
  |
6 |         "like", 20, "programming"
  |                     ^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
  = note: `#[warn(clippy::print_literal)]` on by default
help: try this
  |
5 ~         "\nI doing programming from {1} years and i {0} it",
6 ~         "like", 20
  |

warning: literal with an empty format string
 --> src/main.rs:6:9
  |
6 |         "like", 20, "programming"
  |         ^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
help: try this
  |
5 -         "\nI doing {2} from {1} years and i {0} it",
5 +         "\nI doing {2} from {1} years and i like it", 20, "programming"
  |

warning: `ca_p1` (bin "ca_p1") generated 2 warnings
warning: `ca_p1` (bin "ca_p1" test) generated 2 warnings (2 duplicates)

Meta

rustc --version --verbose:

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-apple-darwin
release: 1.66.0
LLVM version: 15.0.2
Backtrace

<backtrace>

@scontain scontain added the C-bug Category: Clippy is not doing the correct thing label Dec 29, 2022
@Noratrieb
Copy link
Member

This is a clippy bug, not a rustc bug. Can you transfer the issue to the https://github.com/rust-lang/rust-clippy repository?

@matthiaskrgr matthiaskrgr transferred this issue from rust-lang/rust Dec 29, 2022
@xFrednet xFrednet added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 29, 2022
@bors bors closed this as completed in d18d01a Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants