Skip to content

cargo clippy --fix runs without warns on git repository without commit #9838

@TonalidadeHidrica

Description

@TonalidadeHidrica

Summary

When cargo clippy --fix is ran on a crate that is not managed by a VCS, it warns about it and does not modify the code. This also happens if cargo clippy --fix is ran in a git repository that has uncommiteed changes. However, when it is ran on a repository with uncommited changes but without any commit, it modifies the code without an error or a warning.

Reproducer

set -eux

cargo +nightly new repro
cd repro
echo "fn main() { let _ = 0.clone(); }" > src/main.rs
cargo +nightly clippy --fix
cat src/main.rs
+ cargo +nightly new repro
     Created binary (application) `repro` package
+ cd repro
+ echo 'fn main() { let _ = 0.clone(); }'
+ cargo +nightly clippy --fix
    Checking repro v0.1.0 (/home/username/repro)
       Fixed src/main.rs (1 fix)
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
+ cat src/main.rs
fn main() { let _ = 0; }

Version

rustc 1.67.0-nightly (42325c525 2022-11-11)
binary: rustc
commit-hash: 42325c525b9d3885847a3f803abe53c562d289da
commit-date: 2022-11-11
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions