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

fix newline width calc in combine w/ comments #4123

Merged
merged 1 commit into from
Apr 16, 2020

Conversation

calebcartwright
Copy link
Member

Resolves #4031, refs #4110

This address the binding formatting in #4110, but doesn't include any updates for the sub pattern formatting

@@ -188,7 +188,7 @@ pub(crate) fn combine_strs_with_missing_comments(
let missing_comment = rewrite_missing_comment(span, shape, context)?;

if missing_comment.is_empty() {
if allow_extend && prev_str.len() + first_sep.len() + next_str.len() <= shape.width {
if allow_extend && one_line_width <= shape.width {
Copy link
Member Author

Choose a reason for hiding this comment

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

I assume this is indeed a fix and that we don't want to use the full length of next_str. Otherwise next_str can start to exceed the shape width pretty quickly.

For example:

fn foo() {
    match glyph {
        found @ Glyph {
            data: Gl::Com { .. },
            foo: bar,
        } => (),
        _ => (),
    };
}

Remains unchanged by rustfmt, but adding a few more items to the struct (or longer names) will increase the total next_str length and fail the conditional check resulting in a newline insertion.

fn foo() {
    match glyph {
        found @ Glyph {
            data: Gl::Com { .. },
            foo: bar,
            baz: qux,
        } => (),
        _ => (),
    };
}

would be reformatted to the below without this change

fn foo() {
    match glyph {
        found
        @
        Glyph {
            data: Gl::Com { .. },
            foo: bar,
            baz: qux,
        } => (),
        _ => (),
    };
}

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@topecongiro topecongiro merged commit 13a8e54 into rust-lang:master Apr 16, 2020
@calebcartwright calebcartwright deleted the fix-cmb-strs-bugs branch April 17, 2020 23:48
calebcartwright added a commit to calebcartwright/rustfmt that referenced this pull request Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@ binding reformatted strangely on rustfmt from rustc 1.41.0-beta.4
3 participants