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.
This commit is contained in:
Manish Goregaokar 2020-08-02 13:08:42 -07:00 committed by GitHub
commit bf4a37d961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 12 deletions

View File

@ -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);

View File

@ -73,7 +73,6 @@ fn f() {
*/
/* */
/*
@ -81,7 +80,6 @@ fn f() {
Space 6+2: compare A
Ogham Space Mark 6+2: compare B
*/
/**/
/*

View File

@ -0,0 +1,5 @@
// ignore-tidy-trailing-newlines
// pretty-compare-only
/*
*/

View File

@ -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));
}
}