Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some pretty printing tests #37202

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions src/libsyntax/parse/lexer/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use str::char_at;
use std::io::Read;
use std::usize;

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

fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mut Vec<Comment>) {
while is_pattern_whitespace(rdr.ch) && !rdr.is_eof() {
if rdr.col == CharPos(0) && rdr.ch_is('\n') {
if rdr.ch_is('\n') {
push_blank_line_comment(rdr, &mut *comments);
}
rdr.bump();
}
}


fn read_shebang_comment(rdr: &mut StringReader,
code_to_the_left: bool,
comments: &mut Vec<Comment>) {
Expand Down Expand Up @@ -317,14 +316,22 @@ fn read_block_comment(rdr: &mut StringReader,
}


fn consume_comment(rdr: &mut StringReader, code_to_the_left: bool, comments: &mut Vec<Comment>) {
fn consume_comment(rdr: &mut StringReader,
comments: &mut Vec<Comment>,
code_to_the_left: &mut bool,
anything_to_the_left: &mut bool) {
debug!(">>> consume comment");
if rdr.ch_is('/') && rdr.nextch_is('/') {
read_line_comments(rdr, code_to_the_left, comments);
read_line_comments(rdr, *code_to_the_left, comments);
*code_to_the_left = false;
*anything_to_the_left = false;
} else if rdr.ch_is('/') && rdr.nextch_is('*') {
read_block_comment(rdr, code_to_the_left, comments);
read_block_comment(rdr, *code_to_the_left, comments);
*anything_to_the_left = true;
} else if rdr.ch_is('#') && rdr.nextch_is('!') {
read_shebang_comment(rdr, code_to_the_left, comments);
read_shebang_comment(rdr, *code_to_the_left, comments);
*code_to_the_left = false;
*anything_to_the_left = false;
} else {
panic!();
}
Expand Down Expand Up @@ -352,23 +359,29 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,

let mut comments: Vec<Comment> = Vec::new();
let mut literals: Vec<Literal> = Vec::new();
let mut first_read: bool = true;
let mut code_to_the_left = false; // Only code
let mut anything_to_the_left = false; // Code or comments
while !rdr.is_eof() {
loop {
let mut code_to_the_left = !first_read;
// Eat all the whitespace and count blank lines.
rdr.consume_non_eol_whitespace();
if rdr.ch_is('\n') {
code_to_the_left = false;
if anything_to_the_left {
rdr.bump(); // The line is not blank, do not count.
}
consume_whitespace_counting_blank_lines(&mut rdr, &mut comments);
code_to_the_left = false;
anything_to_the_left = false;
}
while rdr.peeking_at_comment() {
consume_comment(&mut rdr, code_to_the_left, &mut comments);
consume_whitespace_counting_blank_lines(&mut rdr, &mut comments);
// Eat one comment group
if rdr.peeking_at_comment() {
consume_comment(&mut rdr, &mut comments,
&mut code_to_the_left, &mut anything_to_the_left);
} else {
break
}
break;
}


let bstart = rdr.pos;
rdr.next_token();
// discard, and look ahead; we're working with internal state
Expand All @@ -384,7 +397,8 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
} else {
debug!("tok: {}", pprust::token_to_string(&tok));
}
first_read = false;
code_to_the_left = true;
anything_to_the_left = true;
}

(comments, literals)
Expand Down
33 changes: 15 additions & 18 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,12 @@ pub trait PrintState<'a> {
}

fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> {
loop {
match self.next_comment() {
Some(ref cmnt) => {
if (*cmnt).pos < pos {
try!(self.print_comment(cmnt));
self.cur_cmnt_and_lit().cur_cmnt += 1;
} else { break; }
}
_ => break
while let Some(ref cmnt) = self.next_comment() {
if cmnt.pos < pos {
try!(self.print_comment(cmnt));
self.cur_cmnt_and_lit().cur_cmnt += 1;
} else {
break
}
}
Ok(())
Expand Down Expand Up @@ -581,7 +578,9 @@ pub trait PrintState<'a> {
Ok(())
}
comments::Trailing => {
try!(word(self.writer(), " "));
if !self.is_bol() {
try!(word(self.writer(), " "));
}
if cmnt.lines.len() == 1 {
try!(word(self.writer(), &cmnt.lines[0]));
hardbreak(self.writer())
Expand Down Expand Up @@ -1715,6 +1714,7 @@ impl<'a> State<'a> {
for (i, st) in blk.stmts.iter().enumerate() {
match st.node {
ast::StmtKind::Expr(ref expr) if i == blk.stmts.len() - 1 => {
try!(self.maybe_print_comment(st.span.lo));
try!(self.space_if_not_bol());
try!(self.print_expr_outer_attr_style(&expr, false));
try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi)));
Expand Down Expand Up @@ -2604,6 +2604,7 @@ impl<'a> State<'a> {
}
try!(self.cbox(INDENT_UNIT));
try!(self.ibox(0));
try!(self.maybe_print_comment(arm.pats[0].span.lo));
try!(self.print_outer_attributes(&arm.attrs));
let mut first = true;
for p in &arm.pats {
Expand Down Expand Up @@ -3007,15 +3008,11 @@ impl<'a> State<'a> {
_ => return Ok(())
};
if let Some(ref cmnt) = self.next_comment() {
if (*cmnt).style != comments::Trailing { return Ok(()) }
if cmnt.style != comments::Trailing { return Ok(()) }
let span_line = cm.lookup_char_pos(span.hi);
let comment_line = cm.lookup_char_pos((*cmnt).pos);
let mut next = (*cmnt).pos + BytePos(1);
if let Some(p) = next_pos {
next = p;
}
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
span_line.line == comment_line.line {
let comment_line = cm.lookup_char_pos(cmnt.pos);
let next = next_pos.unwrap_or(cmnt.pos + BytePos(1));
if span.hi < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
self.print_comment(cmnt)?;
self.cur_cmnt_and_lit.cur_cmnt += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// The problem was specified to casting to `*`, as creating unsafe
// pointers was not being fully checked. Issue #20791.

// pretty-expanded FIXME #23616

fn main() {
let x: &i32;
let y = x as *const i32; //~ ERROR use of possibly uninitialized variable: `*x`
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/coherence-cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

// aux-build:coherence_lib.rs

// pretty-expanded FIXME #23616

// Test that the `Pair` type reports an error if it contains type
// parameters, even when they are covered by local types. This test
// was originally intended to test the opposite, but the rules changed
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/coherence-vec-local-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

// aux-build:coherence_lib.rs

// pretty-expanded FIXME #23616

extern crate coherence_lib as lib;
use lib::Remote;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/coherence-vec-local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

// aux-build:coherence_lib.rs

// pretty-expanded FIXME #23616

extern crate coherence_lib as lib;
use lib::Remote;

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-13352.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pretty-expanded FIXME #23616

fn foo(_: Box<FnMut()>) {}

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-19482.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// Test that a partially specified trait object with unspecified associated
// type does not type-check.

// pretty-expanded FIXME #23616

trait Foo {
type A;

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/meta-expected-error-correct-rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

// revisions: a
// pretty-expanded FIXME #23616

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

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/meta-expected-error-wrong-rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// revisions: a
// should-fail
// pretty-expanded FIXME #23616

// This is a "meta-test" of the compilertest framework itself. In
// particular, it includes the right error message, but the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// Test that the lifetime from the enclosing `&` is "inherited"
// through the `Box` struct.

// pretty-expanded FIXME #23616

#![allow(dead_code)]

trait Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// Test that the lifetime from the enclosing `&` is "inherited"
// through the `MyBox` struct.

// pretty-expanded FIXME #23616

#![allow(dead_code)]
#![feature(rustc_error)]

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/variance-trait-matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pretty-expanded FIXME #23616

#![allow(dead_code)]

// Get<T> is covariant in T
Expand Down
1 change: 0 additions & 1 deletion src/test/pretty/for-comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ fn f(v: &[isize]) -> isize {
for e in v {
n = *e; // This comment once triggered pretty printer bug
}

n
}
2 changes: 0 additions & 2 deletions src/test/run-fail/divide-by-zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:attempt to divide by zero

fn main() {
Expand Down
4 changes: 0 additions & 4 deletions src/test/run-fail/glob-use-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

// Issue #7580

// ignore-pretty
//
// Expanded pretty printing causes resolve conflicts.

// error-pattern:panic works

use std::*;
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/mod-zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:attempt to calculate the remainder with a divisor of zero

fn main() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/run-fail/overflowing-add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to add with overflow'
// compile-flags: -C debug-assertions


fn main() {
let _x = 200u8 + 200u8 + 200u8;
}
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-lsh-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-lsh-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-lsh-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-lsh-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift left with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to multiply with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-neg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to negate with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-rsh-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-rsh-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
// compile-flags: -C debug-assertions

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-fail/overflowing-rsh-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty : (#23623) problems when ending with // comments

// error-pattern:thread 'main' panicked at 'attempt to shift right with overflow'
// compile-flags: -C debug-assertions

Expand Down
Loading