Skip to content

Commit 0d3915b

Browse files
committed
Factor out processing Rustc::Message
1 parent c45b8e9 commit 0d3915b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

util/process_wrapper/rustc.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ pub(crate) fn process_json(line: String, error_format: ErrorFormat) -> LineOutpu
7373
)
7474
});
7575
match parsed.try_into() {
76-
Ok(RustcMessage::Message(msg)) => match error_format {
77-
// If the output should be json, we just forward the messages as-is
78-
// using `line`.
79-
ErrorFormat::Json => LineOutput::Message(line),
80-
// Otherwise we return the rendered field.
81-
_ => LineOutput::Message(msg),
82-
},
76+
Ok(RustcMessage::Message(rendered)) => output_based_on_error_format(line, rendered, error_format),
8377
_ => LineOutput::Skip,
8478
}
8579
}
@@ -89,6 +83,7 @@ pub(crate) fn process_json(line: String, error_format: ErrorFormat) -> LineOutpu
8983
/// so the compiler can be terminated.
9084
/// This is used to implement pipelining in rules_rust, please see
9185
/// https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199
86+
/// TODO pass a function to handle the emit event and merge with process_json
9287
pub(crate) fn stop_on_rmeta_completion(
9388
line: String,
9489
error_format: ErrorFormat,
@@ -105,13 +100,21 @@ pub(crate) fn stop_on_rmeta_completion(
105100
*kill = true;
106101
LineOutput::Terminate
107102
}
108-
Ok(RustcMessage::Message(msg)) => match error_format {
109-
// If the output should be json, we just forward the messages as-is
110-
// using `line`.
111-
ErrorFormat::Json => LineOutput::Message(line),
112-
// Otherwise we return the rendered field.
113-
_ => LineOutput::Message(msg),
114-
},
103+
Ok(RustcMessage::Message(rendered)) => output_based_on_error_format(line, rendered, error_format),
115104
_ => LineOutput::Skip,
116105
}
117106
}
107+
108+
fn output_based_on_error_format(
109+
line: String,
110+
rendered: String,
111+
error_format: ErrorFormat,
112+
) -> LineOutput {
113+
match error_format {
114+
// If the output should be json, we just forward the messages as-is
115+
// using `line`.
116+
ErrorFormat::Json => LineOutput::Message(line),
117+
// Otherwise we return the rendered field.
118+
ErrorFormat::Rendered => LineOutput::Message(rendered),
119+
}
120+
}

0 commit comments

Comments
 (0)