Repository navigation
Conversation
|
So #6651 changed default behavior that we didn't catch? |
Darn, at the time it didn't occur to me that |
My understanding is that yes we do, 1.100 is current beta, 9 days out to next stable. Let me prep a revert series. We'd need to sync the revert series too. |
|
I don’t think it changes default formatting. By default no widths are explicitly set, so they all come from small heuristics, which are based on With someone setting explicit width properties (e.g.
|
Ah right, my bad, it would not be stable default formatting, it would need stable options.
@csmulhern no need to be; it just didn't occur to me at the time. The fix is still very appreciated! |
Ah cool, that sounds good. To be safe, I think we should still land the revert on beta, then reland #6651 + #7152 + this change after the release cycling just to give the combined change some more time to bake across two release cycles. (A fix-forward with this PR is somewhat appealing but I tend to want to be very conservative with backports, since fix-forwards can introduce new bugs and we'd not have enough time to fix any of those in the 1.100 beta.) |
|
Yup, same thoughts here. I'm all for being conservative given the low margin for error. |
This comment has been minimized.
This comment has been minimized.
[beta] Revert "Fixes adjustment of `max_width` within macros" (rust-lang/rustfmt#6651) and follow-up (rust-lang/rustfmt#7152) rust-lang/rust side beta-backport of rust-lang/rustfmt#7222. Part of rust-lang/rustfmt#7223. Closes rust-lang/rustfmt#7223. See rust-lang/rustfmt#7221 (comment). This PR reverts both: 1. rust-lang/rustfmt#6651 (partially; I kept the baseline test commit but not the actual formatting change commit), and 2. rust-lang/rustfmt#7152 (follow-up fix) r? @ytmimi
[beta] Revert "Fixes adjustment of `max_width` within macros" (rust-lang/rustfmt#6651) and follow-up (rust-lang/rustfmt#7152) rust-lang/rust side beta-backport of rust-lang/rustfmt#7222. Part of rust-lang/rustfmt#7223. Closes rust-lang/rustfmt#7223. See rust-lang/rustfmt#7221 (comment). This PR reverts both: 1. rust-lang/rustfmt#6651 (partially; I kept the baseline test commit but not the actual formatting change commit), and 2. rust-lang/rustfmt#7152 (follow-up fix) r? @ytmimi
[beta] Revert "Fixes adjustment of `max_width` within macros" (rust-lang/rustfmt#6651) and follow-up (rust-lang/rustfmt#7152) rust-lang/rust side beta-backport of rust-lang/rustfmt#7222. Part of rust-lang/rustfmt#7223. Closes rust-lang/rustfmt#7223. See rust-lang/rustfmt#7221 (comment). This PR reverts both: 1. rust-lang/rustfmt#6651 (partially; I kept the baseline test commit but not the actual formatting change commit), and 2. rust-lang/rustfmt#7152 (follow-up fix) r? @ytmimi
|
Reminder, once the PR becomes ready for a review, use |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
There was a problem hiding this comment.
Thanks. AFAICT this is correct and only removes the warning but does not modify stable default formatting or stable options formatting.
Minor nits re. comments and test coverage.
@rustbot author
| // NB: we need to either saturate or report an error (or some kind of testable | ||
| // warning). I picked to saturate here. |
There was a problem hiding this comment.
Probably yeet this comment now, it's kinda "duh" on hindsight.
| /// Reduces the maximum width of the configuration. | ||
| /// | ||
| /// This method is intended to be used when creating a forked | ||
| /// configuration for a particular formatting context in which the | ||
| /// total available width needs to be reduced. This reduces the | ||
| /// size of max_width, and recalculates all other properties | ||
| /// affected by small heuristics. Properties set explicitly keep | ||
| /// their value, limited to the new max_width. | ||
| /// | ||
| /// As an example use case, this method is used when formatting | ||
| /// arms within a declarative macro. |
There was a problem hiding this comment.
[COMMENT 1/3]: Can we dedup these comment bodies? It's quite verbose. Consider instead
Reduce
max_widthbydeltasaturating on underflow. Seeadjust_max_width.
ditto for increase_max_width, but saturating on overflow.
| /// Increases the maximum width of the configuration. | ||
| /// | ||
| /// This method is intended to be used when creating a forked | ||
| /// configuration for a particular formatting context in which the | ||
| /// total available width needs to be increased. This increases the | ||
| /// size of max_width, and recalculates all other properties | ||
| /// affected by small heuristics. Properties set explicitly keep | ||
| /// their value. | ||
| /// | ||
| /// As an example use case, this method is used when formatting | ||
| /// arms within a declarative macro. |
There was a problem hiding this comment.
[COMMENT 2/3]: see [COMMENT 1/3].
| /// limited to the new max_width. | ||
| /// | ||
| /// As an example use case, this method is used when formatting | ||
| /// arms within a declarative macro. |
There was a problem hiding this comment.
[COMMENT 3/3]: Probably easier to read if we say sth like
Adjust
max_widthbydeltain a forked config (example: macro body at zero indent). In particular:
- Width options not set explicitly are recomputed from new
max_widthvia heuristics.- Explicit widths will keep their value but capped at the new
max_width.A later increase in
max_widthwill not restore a previously capped value.
There was a problem hiding this comment.
That example you gave in the PR is great, would be nice to have it as an additional test case 😉
| () => { | ||
| m!(aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbb, cccccccccccccccc, dddddddddddddddd); | ||
| }; | ||
| } |
There was a problem hiding this comment.
NB: I was looking at the logic here a bit more closely. I know obviously that the ui tests here won't demonstrate "ah the warning went away" (that's #6933), which is the point for this PR.
So my understanding is that, there's 3 cases we need to consider:
- Explicit width never set, i.e. default config
- Explicit width configured, but:
- (A) > recomputed (reduced) max width, so it has to be capped to recomputed max width.
- (B) <= recomputed (reduced) max width, so fits in recomputed max width.
Here:
- (1) unaffected.
- (2A) is stable option behavior (though it has a warning à la Cannot set granular width configuration settings to 100% if
max_width = 100#5404), and we're not changing it modulo removing the cap warning. - (2B) is stable option behavior, and unchanged by this PR.
This is an update to #6651. Since updating to the rustfmt beta that includes that change, I noticed that explicitly set widths that are involved in small heuristics can now cause formatting differences between the same code inside and outside of a macro.
The original sin that makes this space challenging is how macros are formatted by forking the config and formatting the macro body as if it had zero indent + reduced max width. Because of this, #6651 reduced the width of all the other explicit width properties that are involved in small heuristics. However, these properties are applied independent of indent. This PR fixes this inconsistency for explicitly set widths by not modifying the values beyond capping them based on
max_width. Note: there are still likely other ways that macro bodies format inconsistently, due to the original sin.The tests have been updated to account for this nuance.
As a quick example, here is code that formats inconsistently today:
The code formats consistently with this change.