From 49cae9c48566a37dd4e8bcab69c8598dc0343ee9 Mon Sep 17 00:00:00 2001 From: Sinh Pham Date: Sat, 22 Aug 2015 18:08:11 -0400 Subject: [PATCH] Fix https://github.com/nrc/rustfmt/issues/190 --- src/missed_spans.rs | 4 ++++ tests/target/no_new_line_beginning.rs | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 tests/target/no_new_line_beginning.rs diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 64025550410..aa1d4679e9a 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -43,6 +43,10 @@ impl<'a> FmtVisitor<'a> { self.codemap.lookup_char_pos(end)); if start == end { + // Do nothing if this is the beginning of the file. + if start == BytePos(0) { + return; + } process_last_snippet(self, "", ""); return; } diff --git a/tests/target/no_new_line_beginning.rs b/tests/target/no_new_line_beginning.rs new file mode 100644 index 00000000000..f79c691f085 --- /dev/null +++ b/tests/target/no_new_line_beginning.rs @@ -0,0 +1,2 @@ +fn main() { +}