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

Compiler error when using --fix on clippy::implicit_saturating_sub #13524

Closed
FreezyLemon opened this issue Oct 8, 2024 · 1 comment · Fixed by #13533
Closed

Compiler error when using --fix on clippy::implicit_saturating_sub #13524

FreezyLemon opened this issue Oct 8, 2024 · 1 comment · Fixed by #13533
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@FreezyLemon
Copy link

Summary

cargo clippy --fix seems to sometimes cause a compiler error when fixing the implicit_saturating_sub lint.

Reproducer

I tried running cargo +nightly clippy --fix on this code:

pub fn test(a: usize, b: usize, c: bool) -> usize {
    if c {
        123
    } else if a >= b {
        0
    } else {
        b - a
    }
}

I expected to see this happen:

pub fn test(a: usize, b: usize, c: bool) -> usize {
    if c {
        123
    } else {
        b.saturating_sub(a)
    }
}

Instead, this happened (compiler error):

pub fn test(a: usize, b: usize, c: bool) -> usize {
    if c {
        17
    } else b.saturating_sub(a)
}

Version

rustc 1.83.0-nightly (3ae715c8c 2024-10-07)
binary: rustc
commit-hash: 3ae715c8c63f9aeac47cbf7d8d9dadb3fa32c638
commit-date: 2024-10-07
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1

Additional Labels

No response

@FreezyLemon FreezyLemon added the C-bug Category: Clippy is not doing the correct thing label Oct 8, 2024
@blyxyas blyxyas added I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ and removed I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Oct 10, 2024
@blyxyas
Copy link
Member

blyxyas commented Oct 10, 2024

Note to future contributos: This is not an ICE, this is a lint that outputs code that is invalid.
I'll go check this out.

bors added a commit that referenced this issue Oct 11, 2024
Fix span issue on `implicit_saturating_sub`

Fixes #13524

changelog: [`implicit_saturating_sub`]: Fix span issue on else blocks
@bors bors closed this as completed in 140a127 Oct 11, 2024
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants