From feb09a42f508e1c9b47089f4b017c6de447e62cb Mon Sep 17 00:00:00 2001 From: DarkDrek Date: Wed, 27 Jan 2016 02:18:05 +0100 Subject: [PATCH] Fix #784 --- src/missed_spans.rs | 8 ++++---- tests/source/comment.rs | 2 ++ tests/target/comment.rs | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/missed_spans.rs b/src/missed_spans.rs index cd69b6dcc80..c86cd62a900 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -147,11 +147,11 @@ impl<'a> FmtVisitor<'a> { if let Some('/') = subslice.chars().skip(1).next() { // Add a newline after line comments self.buffer.push_str("\n"); - } else if line_start < snippet.len() { + } else if line_start <= snippet.len() { // For other comments add a newline if there isn't one at the end already - let c = snippet[line_start..].chars().next().unwrap(); - if c != '\n' && c != '\r' { - self.buffer.push_str("\n"); + match snippet[line_start..].chars().next() { + Some('\n') | Some('\r') => (), + _ => self.buffer.push_str("\n"), } } diff --git a/tests/source/comment.rs b/tests/source/comment.rs index 714b77b081c..8cfde87f8c4 100644 --- a/tests/source/comment.rs +++ b/tests/source/comment.rs @@ -45,3 +45,5 @@ fn chains() { /* * random comment */ + +fn main() {/* Test */} diff --git a/tests/target/comment.rs b/tests/target/comment.rs index 28740749c5d..98815ac5403 100644 --- a/tests/target/comment.rs +++ b/tests/target/comment.rs @@ -46,3 +46,7 @@ fn chains() { } // random comment + +fn main() { + // Test +}