Skip to content

Commit d2e6d41

Browse files
committed
process_wrapper shouldn't choke on rustc warnings
Previously " WARN ..." output on stderr would cause process wrapper to give up parsing the json and emit it verbatim. ``` WARN rustc_errors::emitter Invalid span ./snip.rs:49:25: 49:25 (#7), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "./snip.rs" }) } WARN rustc_errors::emitter Invalid span ./snip.rs:49:31: 49:31 (#7), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "./snip.rs" }) } {"$message_type":"diagnostic","message":"expected a literal (`1u8`, `1.0f32`, `\"string\"`, etc.) here, found `concat`","code":null,"level":"error","spans": ... ```
1 parent 6b4edd0 commit d2e6d41

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

util/process_wrapper/main.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ fn process_line(
101101
// with the regular JSON output. Arguably, rustc should be fixed not to emit lines
102102
// like these (or to convert them to JSON), but for now we convert them to JSON
103103
// ourselves.
104-
if line.contains("is not a recognized feature for this target (ignoring feature)") {
104+
if line.contains("is not a recognized feature for this target (ignoring feature)") ||
105+
line.starts_with(" WARN ")
106+
{
105107
if let Ok(json_str) = json_warning(&line).stringify() {
106108
line = json_str;
107109
} else {
@@ -292,33 +294,35 @@ mod test {
292294
}
293295

294296
#[test]
295-
fn test_process_line_llvm_feature_warning() -> Result<(), String> {
297+
fn test_process_line_noise() -> Result<(), String> {
296298
let mut metadata_emitted = false;
297-
let LineOutput::Message(msg) = process_line(
298-
"'+zaamo' is not a recognized feature for this target (ignoring feature)".to_string(),
299-
/*quit_on_rmeta=*/ false,
300-
ErrorFormat::Json,
301-
&mut metadata_emitted,
302-
)?
303-
else {
304-
return Err("Expected a LineOutput::Message".to_string());
305-
};
306-
assert_eq!(
307-
parse_json(&msg)?,
308-
parse_json(
309-
r#"
310-
{
311-
"$message_type": "diagnostic",
312-
"message": "'+zaamo' is not a recognized feature for this target (ignoring feature)",
313-
"code": null,
314-
"level": "warning",
315-
"spans": [],
316-
"children": [],
317-
"rendered": "'+zaamo' is not a recognized feature for this target (ignoring feature)"
318-
}
319-
"#
299+
for msg in ["'+zaamo' is not a recognized feature for this target (ignoring feature)",
300+
" WARN rustc_errors::emitter Invalid span..."] {
301+
let LineOutput::Message(msg) = process_line(
302+
msg.to_string(),
303+
/*quit_on_rmeta=*/ false,
304+
ErrorFormat::Json,
305+
&mut metadata_emitted,
320306
)?
321-
);
307+
else {
308+
return Err("Expected a LineOutput::Message".to_string());
309+
};
310+
assert_eq!(
311+
parse_json(&msg)?,
312+
parse_json(format!(r#"
313+
{
314+
"$message_type": "diagnostic",
315+
"message": "{0}",
316+
"code": null,
317+
"level": "warning",
318+
"spans": [],
319+
"children": [],
320+
"rendered": "{0}"
321+
}
322+
"#, msg)
323+
)?
324+
);
325+
}
322326
Ok(())
323327
}
324328

0 commit comments

Comments
 (0)