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

pprust: adjust mixed comment printing and add regression test for #74745 #74980

Merged
merged 3 commits into from
Aug 2, 2020
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
4 changes: 3 additions & 1 deletion src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions src/test/pretty/block-comment-wchar.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@
*/



/* */

/*
Hello from offset 6
Space 6+2: compare A
Ogham Space Mark 6+2: compare B
*/

/* */

/*
Expand Down
5 changes: 5 additions & 0 deletions src/test/pretty/issue-74745.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ignore-tidy-trailing-newlines
// pretty-compare-only

/*
*/
25 changes: 16 additions & 9 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand Down Expand Up @@ -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),
));
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}
}

Expand Down