Skip to content

Commit 4a91a80

Browse files
committed
Fix some pretty printing tests
1 parent 16eeeac commit 4a91a80

File tree

111 files changed

+72
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+72
-225
lines changed

src/libsyntax/parse/lexer/comments.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use str::char_at;
2424
use std::io::Read;
2525
use std::usize;
2626

27-
#[derive(Clone, Copy, PartialEq)]
27+
#[derive(Clone, Copy, PartialEq, Debug)]
2828
pub enum CommentStyle {
2929
/// No code on either side of each line of the comment
3030
Isolated,
@@ -155,14 +155,13 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment>) {
155155

156156
fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mut Vec<Comment>) {
157157
while is_pattern_whitespace(rdr.ch) && !rdr.is_eof() {
158-
if rdr.col == CharPos(0) && rdr.ch_is('\n') {
158+
if rdr.ch_is('\n') {
159159
push_blank_line_comment(rdr, &mut *comments);
160160
}
161161
rdr.bump();
162162
}
163163
}
164164

165-
166165
fn read_shebang_comment(rdr: &mut StringReader,
167166
code_to_the_left: bool,
168167
comments: &mut Vec<Comment>) {
@@ -317,14 +316,22 @@ fn read_block_comment(rdr: &mut StringReader,
317316
}
318317

319318

320-
fn consume_comment(rdr: &mut StringReader, code_to_the_left: bool, comments: &mut Vec<Comment>) {
319+
fn consume_comment(rdr: &mut StringReader,
320+
comments: &mut Vec<Comment>,
321+
code_to_the_left: &mut bool,
322+
anything_to_the_left: &mut bool) {
321323
debug!(">>> consume comment");
322324
if rdr.ch_is('/') && rdr.nextch_is('/') {
323-
read_line_comments(rdr, code_to_the_left, comments);
325+
read_line_comments(rdr, *code_to_the_left, comments);
326+
*code_to_the_left = false;
327+
*anything_to_the_left = false;
324328
} else if rdr.ch_is('/') && rdr.nextch_is('*') {
325-
read_block_comment(rdr, code_to_the_left, comments);
329+
read_block_comment(rdr, *code_to_the_left, comments);
330+
*anything_to_the_left = true;
326331
} else if rdr.ch_is('#') && rdr.nextch_is('!') {
327-
read_shebang_comment(rdr, code_to_the_left, comments);
332+
read_shebang_comment(rdr, *code_to_the_left, comments);
333+
*code_to_the_left = false;
334+
*anything_to_the_left = false;
328335
} else {
329336
panic!();
330337
}
@@ -352,23 +359,29 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
352359

353360
let mut comments: Vec<Comment> = Vec::new();
354361
let mut literals: Vec<Literal> = Vec::new();
355-
let mut first_read: bool = true;
362+
let mut code_to_the_left = false; // Only code
363+
let mut anything_to_the_left = false; // Code or comments
356364
while !rdr.is_eof() {
357365
loop {
358-
let mut code_to_the_left = !first_read;
366+
// Eat all the whitespace and count blank lines.
359367
rdr.consume_non_eol_whitespace();
360368
if rdr.ch_is('\n') {
361-
code_to_the_left = false;
369+
if anything_to_the_left {
370+
rdr.bump(); // The line is not blank, do not count.
371+
}
362372
consume_whitespace_counting_blank_lines(&mut rdr, &mut comments);
373+
code_to_the_left = false;
374+
anything_to_the_left = false;
363375
}
364-
while rdr.peeking_at_comment() {
365-
consume_comment(&mut rdr, code_to_the_left, &mut comments);
366-
consume_whitespace_counting_blank_lines(&mut rdr, &mut comments);
376+
// Eat one comment group
377+
if rdr.peeking_at_comment() {
378+
consume_comment(&mut rdr, &mut comments,
379+
&mut code_to_the_left, &mut anything_to_the_left);
380+
} else {
381+
break
367382
}
368-
break;
369383
}
370384

371-
372385
let bstart = rdr.pos;
373386
rdr.next_token();
374387
// discard, and look ahead; we're working with internal state
@@ -384,7 +397,8 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
384397
} else {
385398
debug!("tok: {}", pprust::token_to_string(&tok));
386399
}
387-
first_read = false;
400+
code_to_the_left = true;
401+
anything_to_the_left = true;
388402
}
389403

390404
(comments, literals)

src/libsyntax/print/pprust.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,12 @@ pub trait PrintState<'a> {
545545
}
546546

547547
fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> {
548-
loop {
549-
match self.next_comment() {
550-
Some(ref cmnt) => {
551-
if (*cmnt).pos < pos {
552-
try!(self.print_comment(cmnt));
553-
self.cur_cmnt_and_lit().cur_cmnt += 1;
554-
} else { break; }
555-
}
556-
_ => break
548+
while let Some(ref cmnt) = self.next_comment() {
549+
if cmnt.pos < pos {
550+
try!(self.print_comment(cmnt));
551+
self.cur_cmnt_and_lit().cur_cmnt += 1;
552+
} else {
553+
break
557554
}
558555
}
559556
Ok(())
@@ -581,7 +578,9 @@ pub trait PrintState<'a> {
581578
Ok(())
582579
}
583580
comments::Trailing => {
584-
try!(word(self.writer(), " "));
581+
if !self.is_bol() {
582+
try!(word(self.writer(), " "));
583+
}
585584
if cmnt.lines.len() == 1 {
586585
try!(word(self.writer(), &cmnt.lines[0]));
587586
hardbreak(self.writer())
@@ -1715,6 +1714,7 @@ impl<'a> State<'a> {
17151714
for (i, st) in blk.stmts.iter().enumerate() {
17161715
match st.node {
17171716
ast::StmtKind::Expr(ref expr) if i == blk.stmts.len() - 1 => {
1717+
try!(self.maybe_print_comment(st.span.lo));
17181718
try!(self.space_if_not_bol());
17191719
try!(self.print_expr_outer_attr_style(&expr, false));
17201720
try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi)));
@@ -2604,6 +2604,7 @@ impl<'a> State<'a> {
26042604
}
26052605
try!(self.cbox(INDENT_UNIT));
26062606
try!(self.ibox(0));
2607+
try!(self.maybe_print_comment(arm.pats[0].span.lo));
26072608
try!(self.print_outer_attributes(&arm.attrs));
26082609
let mut first = true;
26092610
for p in &arm.pats {
@@ -3007,15 +3008,11 @@ impl<'a> State<'a> {
30073008
_ => return Ok(())
30083009
};
30093010
if let Some(ref cmnt) = self.next_comment() {
3010-
if (*cmnt).style != comments::Trailing { return Ok(()) }
3011+
if cmnt.style != comments::Trailing { return Ok(()) }
30113012
let span_line = cm.lookup_char_pos(span.hi);
3012-
let comment_line = cm.lookup_char_pos((*cmnt).pos);
3013-
let mut next = (*cmnt).pos + BytePos(1);
3014-
if let Some(p) = next_pos {
3015-
next = p;
3016-
}
3017-
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
3018-
span_line.line == comment_line.line {
3013+
let comment_line = cm.lookup_char_pos(cmnt.pos);
3014+
let next = next_pos.unwrap_or(cmnt.pos + BytePos(1));
3015+
if span.hi < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
30193016
self.print_comment(cmnt)?;
30203017
self.cur_cmnt_and_lit.cur_cmnt += 1;
30213018
}

src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// The problem was specified to casting to `*`, as creating unsafe
1313
// pointers was not being fully checked. Issue #20791.
1414

15-
// pretty-expanded FIXME #23616
16-
1715
fn main() {
1816
let x: &i32;
1917
let y = x as *const i32; //~ ERROR use of possibly uninitialized variable: `*x`

src/test/compile-fail/coherence-cow.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
// aux-build:coherence_lib.rs
1414

15-
// pretty-expanded FIXME #23616
16-
1715
// Test that the `Pair` type reports an error if it contains type
1816
// parameters, even when they are covered by local types. This test
1917
// was originally intended to test the opposite, but the rules changed

src/test/compile-fail/coherence-vec-local-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
// aux-build:coherence_lib.rs
1515

16-
// pretty-expanded FIXME #23616
17-
1816
extern crate coherence_lib as lib;
1917
use lib::Remote;
2018

src/test/compile-fail/coherence-vec-local.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
// aux-build:coherence_lib.rs
1515

16-
// pretty-expanded FIXME #23616
17-
1816
extern crate coherence_lib as lib;
1917
use lib::Remote;
2018

src/test/compile-fail/issue-13352.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
12-
1311
fn foo(_: Box<FnMut()>) {}
1412

1513
fn main() {

src/test/compile-fail/issue-19482.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// Test that a partially specified trait object with unspecified associated
1212
// type does not type-check.
1313

14-
// pretty-expanded FIXME #23616
15-
1614
trait Foo {
1715
type A;
1816

src/test/compile-fail/meta-expected-error-correct-rev.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// revisions: a
12-
// pretty-expanded FIXME #23616
1312

1413
// Counterpart to `meta-expected-error-wrong-rev.rs`
1514

src/test/compile-fail/meta-expected-error-wrong-rev.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// revisions: a
1212
// should-fail
13-
// pretty-expanded FIXME #23616
1413

1514
// This is a "meta-test" of the compilertest framework itself. In
1615
// particular, it includes the right error message, but the message

src/test/compile-fail/object-lifetime-default-from-rptr-box-error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// Test that the lifetime from the enclosing `&` is "inherited"
1212
// through the `Box` struct.
1313

14-
// pretty-expanded FIXME #23616
15-
1614
#![allow(dead_code)]
1715

1816
trait Test {

src/test/compile-fail/object-lifetime-default-from-rptr-struct-error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// Test that the lifetime from the enclosing `&` is "inherited"
1212
// through the `MyBox` struct.
1313

14-
// pretty-expanded FIXME #23616
15-
1614
#![allow(dead_code)]
1715
#![feature(rustc_error)]
1816

src/test/compile-fail/variance-trait-matching.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
12-
1311
#![allow(dead_code)]
1412

1513
// Get<T> is covariant in T

src/test/pretty/for-comment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ fn f(v: &[isize]) -> isize {
1717
for e in v {
1818
n = *e; // This comment once triggered pretty printer bug
1919
}
20-
2120
n
2221
}

src/test/run-fail/divide-by-zero.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:attempt to divide by zero
1412

1513
fn main() {

src/test/run-fail/glob-use-std.rs

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
// Issue #7580
1212

13-
// ignore-pretty
14-
//
15-
// Expanded pretty printing causes resolve conflicts.
16-
1713
// error-pattern:panic works
1814

1915
use std::*;

src/test/run-fail/mod-zero.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:attempt to calculate the remainder with a divisor of zero
1412

1513
fn main() {

src/test/run-fail/overflowing-add.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to add with overflow'
1412
// compile-flags: -C debug-assertions
1513

16-
1714
fn main() {
1815
let _x = 200u8 + 200u8 + 200u8;
1916
}

src/test/run-fail/overflowing-lsh-1.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-lsh-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-lsh-3.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-lsh-4.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-mul.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to multiply with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-neg.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to negate with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-rsh-1.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-rsh-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
1412
// compile-flags: -C debug-assertions
1513

src/test/run-fail/overflowing-rsh-3.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-pretty : (#23623) problems when ending with // comments
12-
1311
// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
1412
// compile-flags: -C debug-assertions
1513

0 commit comments

Comments
 (0)