Skip to content

Keep array types on same line as prefix for statics - #6995

Open
Blackgaurd wants to merge 4 commits into
rust-lang:mainfrom
Blackgaurd:fix-6976
Open

Blackgaurd wants to merge 4 commits into
rust-lang:mainfrom
Blackgaurd:fix-6976

Conversation

@Blackgaurd

Copy link
Copy Markdown

Fix for: #6976

Mimicking how types are rewritten in rewrite_struct_field:

  • Try rewriting type by itself on the rest of the line.
  • If it doesn't fit one line, use rewrite_assign_rhs.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Jul 29, 2026
@Blackgaurd Blackgaurd changed the title Fix 6976 Keep array types on same line as prefix for statics Jul 29, 2026
@ytmimi ytmimi self-assigned this Jul 29, 2026

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

Thanks for the PR. Before we can consider moving forward these changes need to be gated because they could impact stable default formatting.

View changes since this review

Comment thread src/items.rs Outdated
Comment thread src/items.rs Outdated
Comment thread tests/source/issue_6976_style_edition_2024.rs
@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Aug 1, 2026
@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@ytmimi ytmimi added A-2027-style-edition Area: style edition 2027 X-requires-next-style-edition Expected formatting impact: can only be done over a style edition (caution) labels Aug 1, 2026
@Blackgaurd

Copy link
Copy Markdown
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Aug 3, 2026
@ytmimi

ytmimi commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Could you add a test case where the array type is so large that it doesn't fit within the max_width even after we place it on the next line. I'd like to see what happens in that case. You can either make the type really long or you can artificially reduce the max_width on that test case to see what happens.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Aug 22, 2026
@Blackgaurd

Copy link
Copy Markdown
Author

I've added such a test case, where the type has width 104 > 100 if put on the second line. I believe its output is desired since it mirrors how a similar case with struct fields are formatted. That is,

pub struct T {
    field_name_that_is_kind_of_really_long1: 
        [ThisTypeIsReallyLongAbcdefghikjlmnopqrstuvwxyz; usernames::constants::USERNAME_LINK_ENTROPY_SIZE],
}

becomes

pub struct T {
    field_name_that_is_kind_of_really_long1: 
        [ThisTypeIsReallyLongAbcdefghikjlmnopqrstuvwxyz; usernames::constants::USERNAME_LINK_ENTROPY_SIZE],
}

So the array type is still split in two, with the first part on the first line, and the second part on the second line.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Sep 8, 2026
Comment on lines +7 to +10
// type is really long that it doesn't fit on the next line
pub(super) const ENCRYPTED_USERNAME_ENTROPY: [ThisTypeIsReallyLongAbcdefghikjlmnopqrstuvwxyz;
usernames::constants::USERNAME_LINK_ENTROPY_SIZE] =
const_str::hex!("4302c613c092a51c5394becffeb6f697300a605348e93f03c3db95e0b03d28f1");

@ytmimi ytmimi Sep 9, 2026

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.

hmmm 🤔 so when the type is too long we still end up with the same formatting that #6976 was hoping to avoid. To be honest, I'm not sure how to handle this right now. I'd like @rust-lang/style to weigh in on this one before moving forward.


Edit: Here's the link to the Zulip discussion: #t-style > Guidance on Array Type wrapping

View changes since the review

@ytmimi ytmimi added the S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-2027-style-edition Area: style edition 2027 S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). S-waiting-on-review Status: awaiting review from the assignee but also interested parties. X-requires-next-style-edition Expected formatting impact: can only be done over a style edition (caution)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants