diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-08-02 13:08:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-02 13:08:42 -0700 |
| commit | bf4a37d9611239fc89f25e0a9c47d71bd43f1450 (patch) | |
| tree | 719cd7331192d4bd1c06a34f70b7cc5e2481903e | |
| parent | 19cefa68640843956eedd86227ddc1d35dbc6754 (diff) | |
| parent | 1530563bd7a3880eec14d78e4a715c1bc4e24074 (diff) | |
| download | rust-bf4a37d9611239fc89f25e0a9c47d71bd43f1450.tar.gz rust-bf4a37d9611239fc89f25e0a9c47d71bd43f1450.zip | |
Rollup merge of #74980 - davidtwco:issue-74745-pprust-regression-test, r=petrochenkov
pprust: adjust mixed comment printing and add regression test for #74745 Fixes #74745. This PR adds a regression test for #74745. While a `ignore-tidy-trailing-lines` header is required, this doesn't stop the test from reproducing, so long as there is no newline at the end of the file. However, adding the header comments made the test fail due to a bug in pprust - so this PR also adjusts the pretty printing of mixed comments so that the initial zero-break isn't emitted at the beginning of the line. Through this, the `block-comment-wchar` test can have the `pp-exact` file removed, as it no longer converges from pretty printing of the source.
| -rw-r--r-- | src/librustc_ast_pretty/pprust.rs | 4 | ||||
| -rw-r--r-- | src/test/pretty/block-comment-wchar.pp | 2 | ||||
| -rw-r--r-- | src/test/pretty/issue-74745.rs | 5 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 25 |
4 files changed, 24 insertions, 12 deletions
diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index b0edb1ca41d..4b228629ad7 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -450,7 +450,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere fn print_comment(&mut self, cmnt: &comments::Comment) { match cmnt.style { comments::Mixed => { - self.zerobreak(); + if !self.is_beginning_of_line() { + self.zerobreak(); + } if let Some((last, lines)) = cmnt.lines.split_last() { self.ibox(0); diff --git a/src/test/pretty/block-comment-wchar.pp b/src/test/pretty/block-comment-wchar.pp index 9317b36ba49..2bfcdd75e15 100644 --- a/src/test/pretty/block-comment-wchar.pp +++ b/src/test/pretty/block-comment-wchar.pp @@ -73,7 +73,6 @@ fn f() { */ - /* */ /* @@ -81,7 +80,6 @@ fn f() { Space 6+2: compare A Ogham Space Mark 6+2: compare B */ - /* */ /* diff --git a/src/test/pretty/issue-74745.rs b/src/test/pretty/issue-74745.rs new file mode 100644 index 00000000000..e255cd6caa8 --- /dev/null +++ b/src/test/pretty/issue-74745.rs @@ -0,0 +1,5 @@ +// ignore-tidy-trailing-newlines +// pretty-compare-only + +/* +*/ \ No newline at end of file diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 9354cc16a9a..940e16720f6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -178,27 +178,30 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma results } -fn print_diff(expected: &str, actual: &str, context_size: usize) { +fn write_diff(expected: &str, actual: &str, context_size: usize) -> String { + use std::fmt::Write; + let mut output = String::new(); let diff_results = make_diff(expected, actual, context_size); for result in diff_results { let mut line_number = result.line_number; for line in result.lines { match line { DiffLine::Expected(e) => { - println!("-\t{}", e); + writeln!(output, "-\t{}", e).unwrap(); line_number += 1; } DiffLine::Context(c) => { - println!("{}\t{}", line_number, c); + writeln!(output, "{}\t{}", line_number, c).unwrap(); line_number += 1; } DiffLine::Resulting(r) => { - println!("+\t{}", r); + writeln!(output, "+\t{}", r).unwrap(); } } } - println!(); + writeln!(output, "").unwrap(); } + output } pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { @@ -655,8 +658,12 @@ impl<'test> TestCx<'test> { ------------------------------------------\n\ {}\n\ ------------------------------------------\n\ - \n", - expected, actual + diff:\n\ + ------------------------------------------\n\ + {}\n", + expected, + actual, + write_diff(expected, actual, 3), )); } } @@ -3227,7 +3234,7 @@ impl<'test> TestCx<'test> { } let expected_string = fs::read_to_string(&expected_file).unwrap(); if dumped_string != expected_string { - print_diff(&expected_string, &dumped_string, 3); + print!("{}", write_diff(&expected_string, &dumped_string, 3)); panic!( "Actual MIR output differs from expected MIR output {}", expected_file.display() @@ -3452,7 +3459,7 @@ impl<'test> TestCx<'test> { println!("normalized {}:\n{}\n", kind, actual); } else { println!("diff of {}:\n", kind); - print_diff(expected, actual, 3); + print!("{}", write_diff(expected, actual, 3)); } } |
