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

Backport PR #4730 #5390

Conversation

davidBar-On
Copy link
Contributor

Backport PR #4730 that fix issue #4689.

Test passes with version = "Two" and verified that no additional test issues are added when version is set to "One".

@ytmimi
Copy link
Contributor

ytmimi commented Jun 18, 2022

@davidBar-On thanks so much for this backport!

When you have a chance can you explicitly set // rustfmt-version: Two at the start of the current test case and then create an additional test case for version=One. I think having both tests cases would be valuable.

@davidBar-On
Copy link
Contributor Author

... set // rustfmt-version: Two at the start of the current test case and then create an additional test case for version=One

Done

src/types.rs Outdated
Comment on lines 947 to 961
match &**args_in {
ast::AngleBracketed(args) => {
if args.args.len() > 1 {
true
} else {
false
}
}
_ => false,
}
Copy link
Contributor

@ytmimi ytmimi Jun 20, 2022

Choose a reason for hiding this comment

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

I think we could simplify this to:

matches!(
    args_in.deref(),
    ast::GenericArgs::AngleBracketed(bracket_args) if bracket_args.args.len() > 1
)

@davidBar-On
Copy link
Contributor Author

I think we could simplify this to: matches!( ...

Done

@calebcartwright
Copy link
Member

If you get a chance can you check to see if this resolves the case @jyn514 mentioned in #4689 (comment) too (and if it does add a test case case for it) 🙏

@davidBar-On
Copy link
Contributor Author

If you get a chance can you check to see if this resolves the case @jyn514 mentioned in #4689 (comment) too ....

I checked and that issue is not resolved by this PR 😞

src/types.rs Outdated
Comment on lines 1055 to 1074
let retry_with_force_newline =
if force_newline || (!result.0.contains('\n') && result.0.len() <= shape.width) {
false
} else {
if items.len() > 1 {
true
} else {
match items[0] {
ast::GenericBound::Trait(ref poly_trait_ref, ..) => {
let segments = &poly_trait_ref.trait_ref.path.segments;
if segments.len() > 1 {
true
} else {
is_segment_with_multi_items_array(&segments[0])
}
}
_ => false,
}
}
};
Copy link
Contributor

@ytmimi ytmimi Jul 3, 2022

Choose a reason for hiding this comment

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

I wonder if it's worth pulling this logic out into a function or a closure to help with the indentation. Something like this:

fn retry_with_force_newline(
    items: &[ast::GenericBound],
    force_newline: bool,
    result: &str,
    shape: Shape,
) -> bool {

    if force_newline || (!result.contains('\n') && result.len() <= shape.width) {
        return false;
    }

    if items.len() > 1 {
        return true;
    }

    if let ast::GenericBound::Trait(ref poly_trait_ref, ..) = items[0] {
        let segments = &poly_trait_ref.trait_ref.path.segments;
        if segments.len() > 1 {
            true
        } else {
            is_segment_with_multi_items_array(&segments[0])
        }
    } else {
        false
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pulled some of the logic into is_segment_with_multi_items_array closure and renamed it to is_item_with_multi_items_array, which I believe is good enough.
Originally, is_segment_with_multi_items_array was specified to reduce indentations. Because of a previous comment about using matches! instead of match, the indentations in the closure were reduces, so it was possible to add more logic into the closure.

Comment on lines +81 to +96
// Some test cases to ensure other cases formatting were not changed
fn f() -> Box<
FnMut() -> Thing<
WithType = LongItemName,
Error = LONGLONGLONGLONGLONGONGEvenLongerErrorNameLongerLonger,
>,
> {
}
fn f() -> Box<
FnMut() -> Thing<
WithType = LongItemName,
Error = LONGLONGLONGLONGLONGONGEvenLongerErrorNameLongerLonger,
> + fmt::Write1
+ fmt::Write2,
> {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

At first glance this formatting in the 2nd case looks off to me, but if the comment is correct and that's the intended formatting then we're good to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As written in the comment before the test cases, these cases were added just to make sure that there is no change to the rustfmt formatting because of the PR changes. Formatting of these test cases was not changed. If the formatting is wrong and it may be changed later, then these test cases may be removed.

Comment on lines +98 to +111
fn foo<F>(foo2: F)
where
F: Fn(
// this comment is deleted
),
{
}
fn foo<F>(foo2: F)
where
F: Fn(
// this comment is deleted
) + fmt::Write,
{
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. It does feel odd that including an additional bound with + would throw off the indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above. Formatting of these test cases was not changed by this PR and they may be removed if their formatting may be changed later.

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.

Thanks for your work on this. I'm happy to move forward with these changes. When you have a moment, can you rebase these changes on the current master so I can merge

@davidBar-On davidBar-On force-pushed the issue-4689-Indentation-on-multiline-single-generic-bound branch from d8d6019 to bb16e04 Compare August 9, 2022 06:21
@davidBar-On
Copy link
Contributor Author

Rebased

@ytmimi ytmimi merged commit ea017d7 into rust-lang:master Aug 9, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Aug 9, 2022

Thanks for backporting this!

@ytmimi ytmimi added the release-notes Needs an associated changelog entry label Aug 9, 2022
@calebcartwright
Copy link
Member

Circling back to this as part of prepping release notes, but this doesn't seem to have actually applied a version gate and is thus introducing breaking formatting changes.

Lmk if I'm simply mistaken or overlooking something, but this should be directly observable in a comparison between the Playground and the latest on master using the snippet I included in the original issue description in #4689.

This needs to be addressed ASAP, either via the addition of version gating or by reverting the associated commit(s)

cc @ytmimi

@calebcartwright calebcartwright removed the release-notes Needs an associated changelog entry label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants