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 match enum OR comment indentation #6086

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

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.

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
2 participants