Repository navigation
Use saturating arithmetics for adjust_max_width - #7152
Merged
Merged
Conversation
Copy-pasta typo.
Instead of overflows, or arguably worse, bitwise reinterpretations. They tend to give us garbage (and massive) indentations.
Member
Author
|
Unfortunately I think this made it to 1.100 beta if I got my release cycle right, so we may need/want to consider a 1.100 beta backport r? @ytmimi (or another rustfmt reviewer) |
adjust_max_widthadjust_max_width
ytmimi
approved these changes
Sep 29, 2026
Contributor
|
@jieyouxu Yeah, let's try to get a beta backport out for this since it made it into 1.100 |
This was referenced Sep 30, 2026
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Sep 30, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Sep 30, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Sep 30, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Oct 1, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Oct 1, 2026
[beta] rustfmt backport Cherry-pick of commits from rust-lang/rustfmt#7152 to address rust-lang/rustfmt#7147. The commits are cherry-picked from the subtree push #163545. Approved in [#t-rustfmt/backports > rustfmt#7152: beta-nominated](https://rust-lang.zulipchat.com/#narrow/channel/621384-t-rustfmt.2Fbackports/topic/rustfmt.237152.3A.20beta-nominated/with/627991509). I suppose this can be rolled up into a combined beta backport too. Anyway. r? @ytmimi
Contributor
|
Added the |
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Oct 3, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
github-actions Bot
pushed a commit
to rust-lang/stdarch
that referenced
this pull request
Oct 5, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
github-actions Bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Oct 5, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
programskillforverification
pushed a commit
to programskillforverification/miri
that referenced
this pull request
Oct 5, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang/rustfmt@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang/rustfmt#7115 (config search behavior) * rust-lang/rustfmt#7095 (potentially breaking) * rust-lang/rustfmt#6396 * rust-lang/rustfmt#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang/rustfmt#7152 --- r? @ytmimi
AzureXuanVerse
pushed a commit
to AzureXuanVerse/rustfmt
that referenced
this pull request
Oct 7, 2026
rustfmt subtree update Subtree update of `rustfmt` to rust-lang@677b954. Created using https://github.com/rust-lang/josh-sync. ### Relnotes worthy (1.101 cycle) https://github.com/rust-lang/rustfmt/pulls?q=is%3Apr+state%3Aclosed+merged%3A2026-09-22..2026-09-30 (excluding the v1.11.0 release prep PR): * rust-lang#7115 (config search behavior) * rust-lang#7095 (potentially breaking) * rust-lang#6396 * rust-lang#7152 (but that's a fix for beta-regression) ### Needs beta backport (targetting 1.100) I will make a beta-targetting cherry-pick with the following PR * rust-lang#7152 --- r? @ytmimi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7147. That was introduced in #6651.
The problem
Previously in
adjust_max_widthwe hadthis will overflow (panic in debug, wraparound in release) if
value < -delta. Forstruct_variant_width, we'd bail with a warningSolution
Properly use saturating arithmetics for {
adjust_max_width,reduce_max_width,increase_max_width}.Also fix wrong doc comment for
increase_max_width.Notes for the reviewer
target/ui test becauseeprintln!warning isn't easily testable, cf.eprintln!warnings are not (easily) testable #6933.as-casts robustly #7151 where we are not handling arithmetics that may overflow or integral casts that may reinterpret or truncate very carefully.I used an LLM to co-review my changes, but did not use it to create changes.