Skip to content

Commit

Permalink
Stop extra newlines from being added after block comments (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
efyang authored and nrc committed Oct 24, 2016
1 parent 4b1c669 commit 1c83c76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/missed_spans.rs
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
@@ -0,0 +1,6 @@
fn main() {
// Line Comment
/* Block Comment */

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

let d = 5;
}

0 comments on commit 1c83c76

Please sign in to comment.