Skip to content

Commit 2d17597

Browse files
committed
Strip out non-diagnostic lines from rustfix input
1 parent a77a65c commit 2d17597

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/tools/compiletest/src/json.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ struct DiagnosticCode {
7979
explanation: Option<String>,
8080
}
8181

82+
pub fn rustfix_diagnostics_only(output: &str) -> String {
83+
output.lines().filter(|line| {
84+
line.starts_with('{') && serde_json::from_str::<Diagnostic>(line).is_ok()
85+
}).collect()
86+
}
87+
8288
pub fn extract_rendered(output: &str) -> String {
8389
output
8490
.lines()
@@ -126,11 +132,17 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) ->
126132
expected_errors
127133
}
128134
Err(error) => {
129-
proc_res.fatal(Some(&format!(
130-
"failed to decode compiler output as json: \
131-
`{}`\nline: {}\noutput: {}",
132-
error, line, output
133-
)));
135+
// Ignore the future compat report message - this is handled
136+
// by `extract_rendered`
137+
if serde_json::from_str::<FutureIncompatReport>(line).is_ok() {
138+
vec![]
139+
} else {
140+
proc_res.fatal(Some(&format!(
141+
"failed to decode compiler output as json: \
142+
`{}`\nline: {}\noutput: {}",
143+
error, line, output
144+
)));
145+
}
134146
}
135147
}
136148
} else {

src/tools/compiletest/src/runtest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,7 @@ impl<'test> TestCx<'test> {
29782978
self.prune_duplicate_outputs(&modes_to_prune);
29792979

29802980
let mut errors = self.load_compare_outputs(&proc_res, TestOutput::Compile, explicit);
2981+
let rustfix_input = json::rustfix_diagnostics_only(&proc_res.stderr);
29812982

29822983
if self.config.compare_mode.is_some() {
29832984
// don't test rustfix with nll right now
@@ -2988,7 +2989,7 @@ impl<'test> TestCx<'test> {
29882989
// This will return an empty `Vec` in case the executed test file has a
29892990
// `compile-flags: --error-format=xxxx` header with a value other than `json`.
29902991
let suggestions = get_suggestions_from_json(
2991-
&proc_res.stderr,
2992+
&rustfix_input,
29922993
&HashSet::new(),
29932994
Filter::MachineApplicableOnly,
29942995
)
@@ -3015,7 +3016,7 @@ impl<'test> TestCx<'test> {
30153016
// Apply suggestions from rustc to the code itself
30163017
let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file).unwrap();
30173018
let suggestions = get_suggestions_from_json(
3018-
&proc_res.stderr,
3019+
&rustfix_input,
30193020
&HashSet::new(),
30203021
if self.props.rustfix_only_machine_applicable {
30213022
Filter::MachineApplicableOnly

0 commit comments

Comments
 (0)