Skip to content

Commit 1c83c76

Browse files
efyangnrc
authored andcommitted
Stop extra newlines from being added after block comments (#1185)
1 parent 4b1c669 commit 1c83c76

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/missed_spans.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ impl<'a> FmtVisitor<'a> {
144144
line_start = offset + subslice.len();
145145

146146
if let Some('/') = subslice.chars().skip(1).next() {
147-
// Add a newline after line comments
148-
self.buffer.push_str("\n");
147+
// check that there are no contained block comments
148+
if !subslice.split('\n')
149+
.map(|s| s.trim_left())
150+
.any(|s| s.len() > 2 && &s[0..2] == "/*") {
151+
// Add a newline after line comments
152+
self.buffer.push_str("\n");
153+
}
149154
} else if line_start <= snippet.len() {
150155
// For other comments add a newline if there isn't one at the end already
151156
match snippet[line_start..].chars().next() {

tests/source/issue-1177.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
// Line Comment
3+
/* Block Comment */
4+
5+
let d = 5;
6+
}

tests/target/issue-1177.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
// Line Comment
3+
// Block Comment
4+
5+
let d = 5;
6+
}

0 commit comments

Comments
 (0)