Skip to content

Fix implicit_saturating_sub suggests wrongly on untyped int literal#16309

Merged
Jarcho merged 1 commit into
rust-lang:masterfrom
profetia:issue16307
Jan 1, 2026
Merged

Fix implicit_saturating_sub suggests wrongly on untyped int literal#16309
Jarcho merged 1 commit into
rust-lang:masterfrom
profetia:issue16307

Conversation

@profetia

@profetia profetia commented Dec 29, 2025

Copy link
Copy Markdown
Member

Closes #16307

changelog: [implicit_saturating_sub] fix wrong suggestions on untyped int literal

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 29, 2025
@rustbot

rustbot commented Dec 29, 2025

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho
Jarcho added this pull request to the merge queue Jan 1, 2026
Merged via the queue into rust-lang:master with commit 7d41f1d Jan 1, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 1, 2026
@profetia

profetia commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

Thank you and happy new year!

@profetia
profetia deleted the issue16307 branch January 24, 2026 20:57
pull Bot pushed a commit to Mattlk13/rust-clippy that referenced this pull request Jul 13, 2026
… { x -= 1 }` rewrite (rust-lang#17404)

Fixes rust-lang#17403

`implicit_saturating_sub` rewrites `if x != 0 { x -= 1 }` into `x =
x.saturating_sub(1)`. `saturating_sub` is only usable in a `const fn`
since Rust 1.47, so in a `const fn` with a lower configured MSRV the
rewrite does not compile.

rust-lang#16309 already added this MSRV check to the `if a
>= b { 0 } else { b - a }` path, but the condition path (`if x != 0 { x
-= 1 }`) was left unguarded. This threads the MSRV into that path and
applies the same check, so the lint stays quiet when the suggested
`saturating_sub` would be too new for the const context.

The lint reads the MSRV but was missing from the list of MSRV affected
lints in the configuration docs, so this registers it there as well.

changelog: [`implicit_saturating_sub`]: respect the configured MSRV in
const contexts for the `if x != 0 { x -= 1 }` rewrite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clippy fix creates broken code with saturating sub

3 participants