Skip to content

Respect the configured MSRV in implicit_saturating_sub's if x != 0 { x -= 1 } rewrite#17404

Open
shulaoda wants to merge 1 commit into
rust-lang:masterfrom
shulaoda:fix/implicit-saturating-sub-const-msrv
Open

Respect the configured MSRV in implicit_saturating_sub's if x != 0 { x -= 1 } rewrite#17404
shulaoda wants to merge 1 commit into
rust-lang:masterfrom
shulaoda:fix/implicit-saturating-sub-const-msrv

Conversation

@shulaoda

@shulaoda shulaoda commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #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.

#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

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 11, 2026
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implicit_saturating_sub ignores the configured MSRV for the if x != 0 { x -= 1 } rewrite in a const fn

3 participants