rust-lang / rust-lang/rust-clippy

Clippy Auto-fix causes error

Open
#8,827 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-suggestion-causes-error
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

When running cargo clippy --fix, clippy changes this:
cli/src/run_script.rs

let status = run_in_shell::run(&script, shell);

to this:

let status = run_in_shell::run(script, shell);

which causes an error.

Full command log
    Checking run_in_shell v0.1.0 (E:\projects\vortex\run_in_shell)
    Checking validate_package_name v0.1.0 (E:\projects\vortex\validate_package_name)
    Checking install_npm v0.1.0 (E:\projects\vortex\install_npm)
    Checking vortex v0.1.0 (E:\projects\vortex\cli)
warning: failed to automatically apply fixes suggested by rustc to crate `vortex`      

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

  • cli\src\run_script.rs
  • cli\src\subcommands..\run_script.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: expected one of !, ), ,, ., ::, ?, {, or an operator, found shell
--> cli\src\run_script.rs:28:43
|
28 | let status = run_in_shell::run(script shell);
| -^^^^^ expected one of 8 possible tokens
| |
| help: missing ,

error: expected one of !, ), ,, ., ::, ?, {, or an operator, found shell
--> cli\src\subcommands..\run_script.rs:28:43
|
28 | let status = run_in_shell::run(script shell);
| -^^^^^ expected one of 8 possible tokens
| |
| help: missing ,

error: aborting due to 2 previous errors

Original diagnostics will follow.

warning: you seem to be trying to use match for destructuring a single pattern. Consider using if let
--> cli\src\main.rs:19:9
|
19 | / match color_eyre::install() {
20 | | Err() => {
21 | | eprintln!(
22 | | "{} failed to install {} panic hook, using release {}",
... |
29 | | _ => {}
30 | | }
| |
_______^
|
= note: #[warn(clippy::single_match)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
help: try this
|
19 ~ if let Err(
) = color_eyre::install() {
20 + eprintln!(
21 + "{} failed to install {} panic hook, using release {}",
22 + "warn:".yellow().bold(),
23 + "color-eyre".italic(),
24 + "panic_hook".italic()
...

warning: vortex (bin "vortex" test) generated 1 warning
warning: vortex (bin "vortex") generated 1 warning (1 duplicate)
Finished dev [unoptimized + debuginfo] target(s) in 5.41s


also the space between "script shell" on this line:

28 |     let status = run_in_shell::run(script shell);

is what is in the output, but the comma is there

Reproducer

I tried this code: https://github.com/skyfallwastaken/vortex

I expected to see this happen:
No error

Instead, this happened:
Auto-derefs the argument, which causes errors

Version
rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-pc-windows-msvc
release: 1.60.0
LLVM version: 14.0.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cli/src/run_script.rs and the corresponding cli/src/subcommands/..\run_script.rs path shown in the command output. Reproduce the problem with cargo clippy --fix using the linked vortex example and inspect the generated call syntax. Done means the auto-fix no longer produces malformed Rust and the crate checks successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.