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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ impl<'a> FmtVisitor<'a> {
line_start = offset + subslice.len();

if let Some('/') = subslice.chars().skip(1).next() {
// Add a newline after line comments
self.buffer.push_str("\n");
// check that there are no contained block comments
if !subslice.split('\n')
.map(|s| s.trim_left())
.any(|s| s.len() > 2 && &s[0..2] == "/*") {
// Add a newline after line comments
self.buffer.push_str("\n");
}
} else if line_start <= snippet.len() {
// For other comments add a newline if there isn't one at the end already
match snippet[line_start..].chars().next() {
Expand Down
6 changes: 6 additions & 0 deletions tests/source/issue-1177.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
// Line Comment
/* Block Comment */

let d = 5;
}
6 changes: 6 additions & 0 deletions tests/target/issue-1177.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
// Line Comment
// Block Comment

let d = 5;
}