Skip to content

Stop extra newlines from being added after block comments #1185

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

Merged
merged 1 commit into from
Oct 24, 2016
Merged

Stop extra newlines from being added after block comments #1185

merged 1 commit into from
Oct 24, 2016

Conversation

efyang
Copy link
Contributor

@efyang efyang commented Oct 9, 2016

This PR closes #1177. Essentially rustfmt was reformatting the whole string of // comment \n /* block comment */, but was only checking the beginning of that string to determine whether it was a line comment or not, and thus adding the extra newline.

@nrc
Copy link
Member

nrc commented Oct 9, 2016

Could you add a test for this please?

@efyang
Copy link
Contributor Author

efyang commented Oct 10, 2016

Sure, will do.

@nrc
Copy link
Member

nrc commented Oct 10, 2016

Travis bug looks spurious to me.

// check that there are no contained block comments
if !subslice.chars()
.filter(|&c| c != '\t' && c != ' ')
.collect::<String>()
Copy link
Member

Choose a reason for hiding this comment

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

could this be done more efficiently? Am I right that you only want to trim leading whitespace? So you should be able to use trim and then contains, without needing to collect?

Copy link
Contributor Author

@efyang efyang Oct 11, 2016

Choose a reason for hiding this comment

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

Not just leading, but all whitespace besides newlines, as subslice in this case would be // comment \n /* block comment */, which trim wouldn't work on. Although I guess I could also split by newlines and check the start of every trimmed line, which might be a little bit faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other solution is to change the CommentCodeSlices iterator so that it actually processes them separately.

Copy link
Member

Choose a reason for hiding this comment

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

splitting by lines seems fine to me, I think

@efyang
Copy link
Contributor Author

efyang commented Oct 23, 2016

bump?

@nrc
Copy link
Member

nrc commented Oct 24, 2016

bump?

Thanks, sorry for the delay. Github does not notify me when you push a commit, so you need to also comment so I see the changes.

@nrc
Copy link
Member

nrc commented Oct 24, 2016

Thanks for the change, looks good!

@nrc nrc merged commit 1c83c76 into rust-lang:master Oct 24, 2016
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.

rustfmt adds newlines after block comments
2 participants