Skip to content

cargo clippy --fix broken for positional arguments #10128

Closed
@scontain

Description

@scontain

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions