Stop extra newlines from being added after block comments (#1185)

This commit is contained in:
Edward Yang 2016-10-24 14:45:15 -05:00 committed by Nick Cameron
parent 4b1c669037
commit 1c83c76015
3 changed files with 19 additions and 2 deletions

View File

@ -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() {

View File

@ -0,0 +1,6 @@
fn main() {
// Line Comment
/* Block Comment */
let d = 5;
}

View File

@ -0,0 +1,6 @@
fn main() {
// Line Comment
// Block Comment
let d = 5;
}