From 3eef9993af9dc04f5e9d489e3234e5b4060ff893 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 2 Aug 2011 15:25:06 -0700 Subject: [PATCH] Don't pp extra lines after block open when preserving whitespace. Closes #759 --- src/comp/syntax/print/pprust.rs | 16 +++++++++++++++- src/test/bench/shootout-fibo.rs | 1 - src/test/bench/shootout-nbody.rs | 1 - src/test/bench/task-perf-word-count.rs | 1 - src/test/pretty/empty-lines.rs | 7 +++++++ src/test/run-pass/hashmap-memory.rs | 1 - src/test/run-pass/interior-vec.rs | 1 + src/test/run-pass/issue-687.rs | 1 - .../run-pass/pattern-bound-var-in-for-each.rs | 1 - src/test/run-pass/while-prelude-drop.rs | 1 - 10 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 src/test/pretty/empty-lines.rs diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 7533eced7cfa..11e13d6ebe02 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -172,6 +172,20 @@ fn bclose_(s: &ps, span: codemap::span, indented: uint) { } fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } +fn is_begin(s: &ps) -> bool { + alt s.s.last_token() { + pp::BEGIN(_) { true } + _ { false } + } +} + +fn is_end(s: &ps) -> bool { + alt s.s.last_token() { + pp::END. { true } + _ { false } + } +} + fn is_bol(s: &ps) -> bool { ret s.s.last_token() == pp::EOF || s.s.last_token() == pp::hardbreak_tok(); @@ -1403,7 +1417,7 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } lexer::blank_line. { // We need to do at least one, possibly two hardbreaks. - pprust::hardbreak_if_not_bol(s); + if is_begin(s) || is_end(s) { hardbreak(s.s) } hardbreak(s.s); } } diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs index 28cf4d9b9c61..f0a2009b2132 100644 --- a/src/test/bench/shootout-fibo.rs +++ b/src/test/bench/shootout-fibo.rs @@ -1,4 +1,3 @@ -// xfail-pretty // -*- rust -*- diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index fedab232e58c..08ef4995ad4e 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -1,4 +1,3 @@ -// xfail-pretty // based on: // http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java diff --git a/src/test/bench/task-perf-word-count.rs b/src/test/bench/task-perf-word-count.rs index 97fea953e3d0..0a6b94c7f2ed 100644 --- a/src/test/bench/task-perf-word-count.rs +++ b/src/test/bench/task-perf-word-count.rs @@ -1,4 +1,3 @@ -// xfail-pretty /** A parallel word-frequency counting program. diff --git a/src/test/pretty/empty-lines.rs b/src/test/pretty/empty-lines.rs new file mode 100644 index 000000000000..87de5ff64c27 --- /dev/null +++ b/src/test/pretty/empty-lines.rs @@ -0,0 +1,7 @@ +// Issue #759 +// Whitespace under block opening should not expand forever + +fn a() -> uint { + + 1u +} \ No newline at end of file diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index d60f45f2da85..6470f4d4206b 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -1,4 +1,3 @@ -// xfail-pretty /** A somewhat reduced test case to expose some Valgrind issues. diff --git a/src/test/run-pass/interior-vec.rs b/src/test/run-pass/interior-vec.rs index 4799a04fa8ee..254a4e51b6bb 100644 --- a/src/test/run-pass/interior-vec.rs +++ b/src/test/run-pass/interior-vec.rs @@ -1,4 +1,5 @@ // xfail-stage0 +// xfail-pretty import rusti::ivec_len; diff --git a/src/test/run-pass/issue-687.rs b/src/test/run-pass/issue-687.rs index b97f9890e81f..1a0e93874f1a 100644 --- a/src/test/run-pass/issue-687.rs +++ b/src/test/run-pass/issue-687.rs @@ -1,5 +1,4 @@ // xfail-stage0 -// xfail-pretty use std; import std::ivec; diff --git a/src/test/run-pass/pattern-bound-var-in-for-each.rs b/src/test/run-pass/pattern-bound-var-in-for-each.rs index 51964c34155d..504aea1d4407 100644 --- a/src/test/run-pass/pattern-bound-var-in-for-each.rs +++ b/src/test/run-pass/pattern-bound-var-in-for-each.rs @@ -1,5 +1,4 @@ // xfail-stage0 -// xfail-pretty // Tests that trans_path checks whether a // pattern-bound var is an upvar (when translating // the for-each body) diff --git a/src/test/run-pass/while-prelude-drop.rs b/src/test/run-pass/while-prelude-drop.rs index e480db6d1066..badd2ae10bf8 100644 --- a/src/test/run-pass/while-prelude-drop.rs +++ b/src/test/run-pass/while-prelude-drop.rs @@ -1,4 +1,3 @@ -// xfail-pretty tag t { a; b(str); }