Skip to content

Commit d018c95

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 d018c95

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

util/process_wrapper/main.rs

Lines changed: 32 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,37 @@ 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 text in [
300+
"'+zaamo' is not a recognized feature for this target (ignoring feature)",
301+
" WARN rustc_errors::emitter Invalid span...",
302+
] {
303+
let LineOutput::Message(msg) = process_line(
304+
text.to_string(),
305+
/*quit_on_rmeta=*/ false,
306+
ErrorFormat::Json,
307+
&mut metadata_emitted,
320308
)?
321-
);
309+
else {
310+
return Err("Expected a LineOutput::Message".to_string());
311+
};
312+
assert_eq!(
313+
parse_json(&msg)?,
314+
parse_json(&format!(
315+
r#"{{
316+
"$message_type": "diagnostic",
317+
"message": "{0}",
318+
"code": null,
319+
"level": "warning",
320+
"spans": [],
321+
"children": [],
322+
"rendered": "{0}"
323+
}}"#,
324+
text
325+
))?
326+
);
327+
}
322328
Ok(())
323329
}
324330

0 commit comments

Comments
 (0)