Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-5892: Type alias generic ident should follow the same linebreak rule as trait #6293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnhuichen
Copy link

@johnhuichen johnhuichen commented Aug 25, 2024

Pull Request Template

Checklist

  • Confirmed that cargo test passes

Related Issues/PRs

#5892

Changes

The type alias formatting uses overlapping code path as trait formatting.

The difference is that type alias doesn't use the logic of rewrite_assign_rhs_with_comments, which checks if the generic bounds should be placed on the next line

Testing

added a test case tests/source/issue-5892.rs

@johnhuichen johnhuichen marked this pull request as ready for review August 25, 2024 06:53
@johnhuichen johnhuichen force-pushed the issue-5892-type-alias-generic-ident-should-be-4-spaces branch from 4ba8d22 to fa07d97 Compare August 25, 2024 06:56
@johnhuichen johnhuichen changed the title Issue-5892: Type alias generic ident should be 4 spaces instead of 8 Issue-5892: Type alias generic ident should follow the same linebreak rule as trait Aug 25, 2024
@johnhuichen johnhuichen force-pushed the issue-5892-type-alias-generic-ident-should-be-4-spaces branch from fa07d97 to c801834 Compare August 25, 2024 13:50
@johnhuichen johnhuichen force-pushed the issue-5892-type-alias-generic-ident-should-be-4-spaces branch 2 times, most recently from 519ffc4 to e79db51 Compare August 31, 2024 17:33
Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Left a few notes mostly on code style, but not really on the substance of the change. It looks like there are two issues being worked here and it'll be easier to review the code if each issue had its own PR. When you get a chance, can you please remove the code changes for rust-lang/style-team#189.

@calebcartwright I'd still want @rust-lang/style to weigh in here and direct us on what the correct line break behavior should be for type aliases.

// Is this right?
type AAAAAAAAAAAAA: BBBBBBBBBBBBBBB<
    CCCCCCCCCCCCCCCCC,
    DDDDDDDDDDDDDDDDD,
    EEEEEEEEEEEEEEEEE,
    FFFFFFFFFFFFFFFFF,
    GGGGGGGGGGGGGGGGG,
    HHHHHHHHHHHHHHHHH,
    IIIIIIIIIIIIIIIII,
>;

// or is this right?
type AAAAAAAAAAAAA:
    BBBBBBBBBBBBBBB<
        CCCCCCCCCCCCCCCCC,
        DDDDDDDDDDDDDDDDD,
        EEEEEEEEEEEEEEEEE,
        FFFFFFFFFFFFFFFFF,
        GGGGGGGGGGGGGGGGG,
        HHHHHHHHHHHHHHHHH,
        IIIIIIIIIIIIIIIII,
    >;

src/items.rs Outdated
Comment on lines 1771 to 1787
match context.config.style_edition() {
style_edition if style_edition < StyleEdition::Edition2024 => {
// 2 = `: `
let shape =
Shape::indented(indent, context.config).offset_left(result.len() + 2)?;
let type_bounds = bounds.rewrite(context, shape).map(|s| format!(": {}", s))?;
result.push_str(&type_bounds);
}
_ => {
let shape =
Shape::indented(indent, context.config).offset_left(result.len())?;
result = rewrite_assign_rhs_with(
context,
result.clone() + ":",
bounds,
shape,
&RhsAssignKind::Bounds,
RhsTactics::ForceNextLineWithoutIndent,
)?;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to use a match here. I would probably write this using an if else since you can avoid an extra level on indentation. Also, let's use <= StyleEdition::Edition2021 for older formatting instead of < StyleEdition::Edition2024. It's easier to grep for Edition2021 to find all the places where we're using the older formatting rules.

src/types.rs Outdated
style_edition @ _ if style_edition <= StyleEdition::Edition2021 => {
style_edition if style_edition <= StyleEdition::Edition2021 => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this change necessary?

Copy link
Author

Choose a reason for hiding this comment

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

not necessary. It was suggested by clippy

.gitignore Outdated
Comment on lines 26 to 28

# nvim local dap settings
.nvim-dap.lua
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's revert this. It's not really part of the fix for this issue

Comment on lines 1 to 14
// rustfmt-style_edition: 2024

impl SomeType {
fn method(&mut self) {
self.array[array_index as usize]
.as_mut()
.expect("thing must exist")
.extra_info = Some(ExtraInfo {
parent,
count: count as u16,
children: children.into_boxed_slice(),
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@johnhuichen can you open up a separate PR for this. These two issue are unrelated, right? Also, can you rename the file to reflect that this isn't rustfmt issue number 189, but rather rust-lang/style-team#189

Copy link
Author

@johnhuichen johnhuichen Aug 31, 2024

Choose a reason for hiding this comment

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

Hi @ytmimi thanks for reviewing. I can separate the two issues

@johnhuichen johnhuichen force-pushed the issue-5892-type-alias-generic-ident-should-be-4-spaces branch from e79db51 to 2152473 Compare September 1, 2024 09:47
@johnhuichen johnhuichen force-pushed the issue-5892-type-alias-generic-ident-should-be-4-spaces branch from 2152473 to b6f5b62 Compare September 1, 2024 09:50
@calebcartwright calebcartwright added blocked Blocked on rustc, an RFC, etc. and removed pr-not-reviewed labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-2024-edition Style Edition 2024 blocked Blocked on rustc, an RFC, etc. p-medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants