Skip to content

Conversation

MarcusGrass
Copy link
Contributor

Fixes #6060

This was a bit tricky.

When the inner item is multiline, identation-count before the actual inner item start throws off the line count.

In the usual case, the inner item doesn't contain indentation, example:

fn simple(
    // pre-comment on a function!?
    i: i32,          // yes, it's possible!
    response: NoWay, // hose
)

in the above case, the inner item is i: i32, no comma, no indentation.

So when calculating whether the inner item is too long to add more spaces already, indentation needs to be
removed beforehand, but only for inner items that have newlines in them. In the below case, the inner item is the entire:

msgs::DecodeError::UnknownRequiredFeature
        | msgs::DecodeError::InvalidValue
        | msgs::DecodeError::ShortRead => 0x4000 | 22

Newlines and indentation all.

If the line does become too long by the comment, it will be split and use the old logic in a branch, I added a test for that as well.

Copy link
Contributor

@shulaoda shulaoda left a comment

Choose a reason for hiding this comment

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

LGTM!

@MarcusGrass
Copy link
Contributor Author

Rebased to master since this had become a bit stale

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.

OR pattern in match arm makes rustfmt forget comment alignment

3 participants