Skip to content

Conversation

folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Jul 22, 2025

tracking issue: #115585

Done here because rust-lang/rustfmt has not been synced for a while and uses a nightly version where cfg_select! is not yet a builtin macro.

r? @ytmimi

See also:

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

Failed to set assignee to ytmimi: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 22, 2025
@folkertdev
Copy link
Contributor Author

@ytmimi seems like I can't officially make you a reviewer, so we'll have to figure out how to merge this: I can r+, or we can find someone else to just greenlight it. The changes only touch rustfmt so I think your approval should suffice.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 23, 2025

Maybe you can't officially assign me, but I should definitely have the ability to r+ this once I've had a chance to take a look.

@calebcartwright
Copy link
Member

I think we might want to hold off on merging this for a tad longer. The style team has been discussing possible formatting prescriptions for the macro in our weekly meetings and while we're getting closer there's still a few things we're trying to iron out - rust-lang/style-team#201

My preference would be to give that another week or two to hopefully avoid double code churn

@joshtriplett
Copy link
Member

joshtriplett commented Jul 30, 2025

I think the proposed formatting looks reasonable, as far as the examples go.

@folkertdev Could you please add some examples that include very long left-hand sides in cfg_select!, that might necessitate wrapping? (It's fine if they don't currently wrap, @traviscross and I just wanted to see some examples and how they turned out with the proposed formatting.)

Please include both examples where the line is overlong, and examples where the user manually wrapped the left-hand side.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch 3 times, most recently from 5b15896 to 89a83da Compare July 30, 2025 20:24
@folkertdev
Copy link
Contributor Author

folkertdev commented Jul 30, 2025

I added some formatting examples. They do in fact already format nicely.

I did just notice that comments on the branches, like below, disappear upon formatting

cfg_select! {
    // This comment will disappear when formatting. 
    any(true) => {}
}

For lazy_static! apparently formatting is just skipped if there is a comment inside anywhere? For macro_rules! I'm not really sure what happens. It just seems to work but I can't find logic that handles comments explicitly.

Does rustfmt have some way of handling this?

@traviscross
Copy link
Contributor

For context, @joshtriplett and I talked about this in the style team meeting, and @folkertdev, if you're interested in working with us on it, we were interested in using this PR to explore possible solutions to the questions we had raised about how to format this, such as what Josh mentioned about long left-hand sides.

If we can work out some good rules in this PR, and use the test cases in it to verify that we're happy with the formatting of all the hard cases that we can think of, then we can write down the rules in the style guide around the behavior that's proposed and that we agree on here.

Generally, our preference, if possible, is some wrapping rule for the LHS that keeps things below the maximum column width and that we can later apply, over a style edition, to normal cfg attributes.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from 89a83da to 08240dd Compare July 30, 2025 23:16
@folkertdev
Copy link
Contributor Author

well, I'd like to see cfg_select! stabilized, so whatever helps that move forward, let's do that.

I added some of the long unbreakable line examples, just so we track their behavior. There we also see that comments inside of the block are dropped which is a bit strange because there we just give a tokenstream to the formatter, and I would have assumed that it handled comments.

For the simple cases I think the current behavior is what we want right? though I assume the => { isn't really taken into account when deciding whether to break or not, which might make the line exceed the line length.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from 08240dd to ccfa107 Compare July 30, 2025 23:41
@rust-log-analyzer

This comment has been minimized.

@traviscross
Copy link
Contributor

For the simple cases I think the current behavior is what we want right?

The trouble is that rustfmt's stability policy is that once it formats a construct, the formatting must remain byte-identical within that style edition. So whatever our behavior for the non-simple cases ends up being what we have to commit to and document in the style guide.

So it's better if we can come up with reasonable rules for the non-common cases as well, so that we can commit to reasonable behavior for those cases too. We're open to and interested in seeing proposed behavior there as part of this PR.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from ccfa107 to 17d516f Compare July 31, 2025 09:10
Copy link
Contributor Author

@folkertdev folkertdev left a comment

Choose a reason for hiding this comment

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

Right, I just meant to say that what we need is refinement, but the broad strokes work as desired.

Comment on lines 1532 to 1535
// The cfg plus ` => {` should stay within the line length.
let rule_shape = shape
.sub_width(" => {".len())
.max_width_error(shape.width, span)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not seem to have the desired effect, am I using this right?

Comment on lines +97 to +115
any(feature = "acdefg", true, true, true, true, true, true, true, true) => {
compile_error!("foo")
}
any(feature = "acdefgh123", true, true, true, true, true, true, true, true) => {
compile_error!("foo")
}
any(
feature = "acdefgh1234",
true,
true,
true,
true,
true,
true,
true,
true
) => {
compile_error!("foo")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently this breaks when the cfg part exceeds 80 characters. I've tried to take the => { into account, but that doesn't seem to have any effect. Also when the rhs really is empty, we'd need to consider => {} for the length.

The above still has issues with comments too, which I'm not sure how to deal with.

So @ytmimi @calebcartwright a rustfmt review is probably also a good idea at this point?

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a very brief look at this the other day and I had some suggestions for changes. I'll do my best to wrap up my review soon.

@joshtriplett
Copy link
Member

#145233 will necessitate an update here.

Also, there should be an update to the style guide, though that can wait until after this PR is working.

@jieyouxu jieyouxu added A-rustfmt T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. F-cfg_select `#![feature(cfg_select)]` labels Aug 15, 2025
@jieyouxu
Copy link
Member

Maybe you can't officially assign me, but I should definitely have the ability to r+ this once I've had a chance to take a look.

@ytmimi it's because rustfmt team doesn't yet have write access on r-l/r despite having r+ permissions. See rust-lang/team#1948.

Kobzol added a commit to Kobzol/rust that referenced this pull request Aug 15, 2025
Autolabel `src/tools/{rustfmt,rust-analyzer}` changes with `T-{rustfmt,rust-analyzer}`

Make e.g. rust-lang#144323 more obvious who should be reviewing it and easier to filter.
@folkertdev
Copy link
Contributor Author

I added the new formatting rule for long key-value meta items. The implementation is a bit hacky though. I'd really appreciate some rustfmt feedback on the general approach here, and whether we can break anything out (maybe the refactor of the macro_rules! logic?).

I also have some practical rustfmt implementation questions:

  • how can I figure out whether the macro will expand to an expression (where potentially the rhs does not need braces)
  • when in an expression context, how can i figure out whether the rhs fits on a single line (i.e. no braces, just a trailing ,)

@rust-log-analyzer

This comment has been minimized.

Comment on lines +321 to +331
overflow::rewrite_with_parens(
context,
&path,
list.iter(),
shape
.sub_width("]".len())
.max_width_error(shape.width, this.span)?,
this.span,
context.config.attr_fn_like_width(),
Some(separator_tactic),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this returns an Unknown error when the list items are too long, e.g.

    anything(
        "some other long long long long long thing long long long long long long long long long long long",
    ) => {
        // abc
    }

I'm not sure what to do with that really: is just bailing completely the right approach, or is there some sort of way to still format this in a somewhat reasonable fashion?

@folkertdev
Copy link
Contributor Author

Just checking in: I'll need some help from the rustfmt devs to move this forward. I'd also be happy to join a T-style meeting to iron out some of the remaining issues.

@traviscross traviscross added T-style Relevant to the style team, which will review and decide on the PR/issue. I-style-nominated Nominated for discussion during a style team meeting. labels Sep 24, 2025
@calebcartwright
Copy link
Member

@folkertdev - haven't been able to make time to look through the full diff but given the failing CI I was wondering whether the wrapping behavior is only being applied in cfg_select contexts or if it was being done more generally (e.g. in cfg attrs)?

While I think the intent is to try to get the wrapping behavior applied consistently in a future style edition, we can only apply it now in the new context of cfg_select

@folkertdev
Copy link
Contributor Author

The changes in src/tools/rustfmt/src/attr.rs copy the existing implementation of cfg attrs, and then modify and use that specifically for the cfg_select rules.

It looks like the current CI error is actually due to a typo in a test file, I'll update that, but the questions from earlier are still open.

re the large diff, I'm happy to break it up into smaller pieces if that's helpful.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from f3acdc9 to 4c80447 Compare October 1, 2025 20:46
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from 4c80447 to fcd14d3 Compare October 1, 2025 21:55
@rust-log-analyzer

This comment has been minimized.

@folkertdev
Copy link
Contributor Author

The reason for the CI failure is now the issue I described in #144323 (comment): the line is too large to fit anyway, so the formatting just bails. That is out of my direct control. I'm not sure what to do about that

@calebcartwright
Copy link
Member

how can I figure out whether the macro will expand to an expression (where potentially the rhs does not need braces)

rustfmt has no way of knowing this, and it's why the style guide had to add clauses like this https://doc.rust-lang.org/nightly/style-guide/expressions.html#match

Do not flatten a right-hand side block containing a single macro call because its expanded form could contain a trailing semicolon.

So the implementation on the rustfmt side (in the match arm body context) is to just preserve the braces

when in an expression context, how can i figure out whether the rhs fits on a single line (i.e. no braces, just a trailing ,)

Can you expand on this question so I can be sure I'm answering the right thing? For example, is the question how to tell whether rustfmt's formatted version of an expression is a single line or multiline construct?

@folkertdev
Copy link
Contributor Author

Well if rustfmt cannot tell expression versus item position apart, then the formatter cannot ever drop the braces on a cfg_select rhs. It might drop them in item context, producing invalid code.

So then my question is kind of moot. @joshtriplett you suggested that the formatter should drop the braces when it could, but it looks like that is just not technically possible then.


So separately, do you have thoughts on what to do if the line is longer than the available width (e.g. when a string literal is just longer than that)?

@calebcartwright
Copy link
Member

So separately, do you have thoughts on what to do if the line is longer than the available width (e.g. when a string literal is just longer than that)?

I'd tend to agree with you that bailing isn't the optimal approach but I think it may still be the most pragmatic, at least as part of this PR (perhaps a separate follow up PR could improve upon that)

so that we can experiment with new formatting rules for long lines
@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from fcd14d3 to d8b72ea Compare October 8, 2025 19:59
@rustbot
Copy link
Collaborator

rustbot commented Oct 8, 2025

This PR was rebased onto a different master 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.

@folkertdev folkertdev force-pushed the cfg-select-builtin-macro-fmt branch from d8b72ea to d52246d Compare October 8, 2025 20:02
@folkertdev
Copy link
Contributor Author

Allright, I just updated the tests to reflect that we just bail on lines that are too long.

I think that leaves one final issue (assuming we're happy with the current formatting of long lines), and that is that comments are dropped from the right-hand side. Is there some standard way to preserve them? They are just not part of the parse tree I think, so maybe some span hackery?

@calebcartwright
Copy link
Member

I think that leaves one final issue (assuming we're happy with the current formatting of long lines), and that is that comments are dropped from the right-hand side. Is there some standard way to preserve them? They are just not part of the parse tree I think, so maybe some span hackery?

Correct. There's either the "just check for any comments in between those spans and if so then bail and remit the original contents to avoid dropping comments" or "try to format the thing as well as any comments in there" which is often unspecified from a style perspective (both in terms of specifics and as a general policy)

As it usually ends up being simpler/less code, we often start with the former and then try to move to the latter as and when possible

@folkertdev
Copy link
Contributor Author

In macro_rules! comments are preserved, so e.g.

macro_rules! foo {
    () => {
        // foo
        1 +                   1
    };
}

formats to the expected

macro_rules! foo {
    () => {
        // foo
        1 + 1
    };
}

So I must be missing something about how that works.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Mismatch at tests/source/cfg_select.rs:116:
     _ => {}
 }
 
-// When there is no way to make the cfg fit, formatting bails.
+// When there is no way to make the line fit, formatting bails.
 cfg_select! {
     feature = "debug-with-rustfmt-long-long-long-long-loooooooonnnnnnnnnnnnnnnggggggffffffffffffffff"
     => {
{ "type": "test", "name": "test::system_tests", "event": "failed", "stdout": "\u001b[2m2025-10-08T21:04:03.637198Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value [] used explicitly for skip_macro_invocations\n\u001b[2m2025-10-08T21:04:03.768228Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_modules\n\u001b[2m2025-10-08T21:04:03.933985Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_imports\nWarning: the `version` option is deprecated. Use `style_edition` instead.\nWarning: the `version` option is deprecated. Use `style_edition` instead.\n\u001b[2m2025-10-08T21:04:03.979463Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value One used explicitly for version\n\u001b[2m2025-10-08T21:04:04.011444Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.076613Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.083325Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.095841Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\nWarning: the `fn_args_layout` option is deprecated. Use `fn_params_layout`. instead\n\u001b[2m2025-10-08T21:04:04.348882Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.381316Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.407508Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_imports\n\u001b[2m2025-10-08T21:04:04.585472Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.591938Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for merge_derives\n\u001b[2m2025-10-08T21:04:04.609679Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.634323Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for wrap_comments\n\u001b[2m2025-10-08T21:04:04.685819Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for imports_indent\n\u001b[2m2025-10-08T21:04:04.685826Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\nWarning: the `merge_imports` option is deprecated. Use `imports_granularity=\"Crate\"` instead\n\u001b[2m2025-10-08T21:04:04.737173Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.782537Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for format_macro_bodies\n\u001b[2m2025-10-08T21:04:04.854316Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:04.857883Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:04.857888Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:04.897047Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\nWarning: the `version` option is deprecated. Use `style_edition` instead.\n\u001b[2m2025-10-08T21:04:05.009676Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.052973Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.065038Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.132145Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_imports\n\u001b[2m2025-10-08T21:04:05.150995Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.154389Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for format_macro_bodies\n\u001b[2m2025-10-08T21:04:05.159112Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for disable_all_formatting\n\u001b[2m2025-10-08T21:04:05.162511Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.171078Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value AlwaysSameLine used explicitly for control_brace_style\n\u001b[2m2025-10-08T21:04:05.172827Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for use_field_init_shorthand\n\u001b[2m2025-10-08T21:04:05.176371Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for wrap_comments\n\u001b[2m2025-10-08T21:04:05.176377Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.183361Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for format_generated_files\n\u001b[2m2025-10-08T21:04:05.188347Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for format_generated_files\n\u001b[2m2025-10-08T21:04:05.190040Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for format_generated_files\n\u001b[2m2025-10-08T21:04:05.191735Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 100 used explicitly for doc_comment_code_block_width\n\u001b[2m2025-10-08T21:04:05.193772Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 100 used explicitly for doc_comment_code_block_width\n\u001b[2m2025-10-08T21:04:05.197722Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for merge_derives\n\u001b[2m2025-10-08T21:04:05.205005Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for condense_wildcard_suffixes\n\u001b[2m2025-10-08T21:04:05.213362Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for match_arm_blocks\n\u001b[2m2025-10-08T21:04:05.216738Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_imports\n\u001b[2m2025-10-08T21:04:05.218424Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for reorder_impl_items\n\u001b[2m2025-10-08T21:04:05.221879Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for wrap_comments\n\u001b[2m2025-10-08T21:04:05.225404Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 80 used explicitly for comment_width\n\u001b[2m2025-10-08T21:04:05.227088Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for spaces_around_ranges\n\u001b[2m2025-10-08T21:04:05.234463Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Vertical used explicitly for trailing_comma\n\u001b[2m2025-10-08T21:04:05.237962Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for fn_single_line\n\u001b[2m2025-10-08T21:04:05.241334Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.245058Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.245063Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.247147Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.247152Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.247154Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.254293Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.257777Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.261390Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.264853Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.266624Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.268450Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.270181Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.271875Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.292766Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Tall used explicitly for fn_params_layout\n\u001b[2m2025-10-08T21:04:05.298077Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for force_multiline_blocks\n\u001b[2m2025-10-08T21:04:05.304138Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value SameLineWhere used explicitly for brace_style\n\u001b[2m2025-10-08T21:04:05.311061Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value SameLineWhere used explicitly for brace_style\n\u001b[2m2025-10-08T21:04:05.312796Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for match_block_trailing_comma\n\u001b[2m2025-10-08T21:04:05.319632Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for force_explicit_abi\n\u001b[2m2025-10-08T21:04:05.321293Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.323050Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for indent_style\n\u001b[2m2025-10-08T21:04:05.323055Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 4 used explicitly for tab_spaces\n\u001b[2m2025-10-08T21:04:05.331133Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for reorder_modules\n\u001b[2m2025-10-08T21:04:05.342118Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 50 used explicitly for single_line_let_else_max_width\n\u001b[2m2025-10-08T21:04:05.346223Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Wide used explicitly for type_punctuation_density\n\u001b[2m2025-10-08T21:04:05.348046Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for normalize_comments\n\u001b[2m2025-10-08T21:04:05.353946Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.356339Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Default used explicitly for use_small_heuristics\n\u001b[2m2025-10-08T21:04:05.363599Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for empty_item_single_line\n\u001b[2m2025-10-08T21:04:05.365259Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Block used explicitly for imports_indent\n\u001b[2m2025-10-08T21:04:05.365263Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Mixed used explicitly for imports_layout\n\u001b[2m2025-10-08T21:04:05.366947Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value Never used explicitly for match_arm_leading_pipes\n\u001b[2m2025-10-08T21:04:05.372462Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for format_macro_matchers\n\u001b[2m2025-10-08T21:04:05.381505Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for use_try_shorthand\n\u001b[2m2025-10-08T21:04:05.386708Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 10 used explicitly for short_array_element_width_threshold\n\u001b[2m2025-10-08T21:04:05.391834Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for hard_tabs\n\u001b[2m2025-10-08T21:04:05.395178Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for format_strings\n\u001b[2m2025-10-08T21:04:05.395184Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for error_on_line_overflow\n\u001b[2m2025-10-08T21:04:05.398987Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value false used explicitly for normalize_doc_attributes\n\u001b[2m2025-10-08T21:04:05.402363Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value true used explicitly for remove_nested_parens\n\u001b[2m2025-10-08T21:04:05.415091Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for style_edition\n\u001b[2m2025-10-08T21:04:05.459134Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mrustfmt_nightly::test\u001b[0m\u001b[2m:\u001b[0m Default value 2015 used explicitly for edition\nRan 619 system tests.\n\nthread '<unnamed>' (58398) panicked at src/tools/rustfmt/src/test/mod.rs:189:9:\nassertion `left == right` failed: 1 system tests failed\n  left: 1\n right: 0\nstack backtrace:\n   0: __rustc::rust_begin_unwind\n   1: core::panicking::panic_fmt\n   2: core::panicking::assert_failed_inner\n   3: core::panicking::assert_failed::<u32, u32>\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n\nthread 'test::system_tests' (58397) panicked at src/tools/rustfmt/src/test/mod.rs:80:10:\nFailed to join a test thread: Any { .. }\nstack backtrace:\n   0: __rustc::rust_begin_unwind\n   1: core::panicking::panic_fmt\n   2: core::result::unwrap_failed\n   3: <rustfmt_nightly::test::system_tests::{closure#0} as core::ops::function::FnOnce<()>>::call_once\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n" }
test test::idempotence_tests ... ok

test result: FAILED. 181 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.21s

error: test failed, to rerun pass `--lib`

@fmease fmease removed the A-rustfmt label Oct 8, 2025
@folkertdev
Copy link
Contributor Author

By playing with the spans I got comments in the rhs to work. However, we can't really format the rules that just use a comma. That needs extra logic. Also comments on the branches get dropped still.

So yeah, this is really finicky and especially when playing with the spans building rustfmt takes minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-cfg_select `#![feature(cfg_select)]` I-style-nominated Nominated for discussion during a style team meeting. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. T-style Relevant to the style team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants