Skip to content

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

Merged
rustbot merged 1 commit into
rust-lang:masterfrom
shulaoda:fix/implicit-saturating-sub-const-msrv
Jul 13, 2026
Merged

Respect the configured MSRV in implicit_saturating_sub's if x != 0 { x -= 1 } rewrite#17404
rustbot merged 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

@rustbot rustbot removed the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Jul 13, 2026
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho for the project review.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, llogiq

@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.

@rustbot
rustbot added this pull request to the merge queue Jul 13, 2026
Merged via the queue into rust-lang:master with commit ca697b3 Jul 13, 2026
11 of 13 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 13, 2026
@shulaoda
shulaoda deleted the fix/implicit-saturating-sub-const-msrv branch July 13, 2026 12:58
@shulaoda

Copy link
Copy Markdown
Contributor Author

Thank you, everyone! 🙏

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.

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

5 participants