Code review feedback.

This commit is contained in:
James Leitch 2021-04-19 12:26:04 -07:00
parent b5c194f3f7
commit b3a7953cae

View file

@ -319,13 +319,13 @@ impl CargoActor {
read_at_least_one_message = true; read_at_least_one_message = true;
// Try to deserialize a message from Cargo. // Try to deserialize a message from Cargo or Rustc.
{ let mut deserializer = serde_json::Deserializer::from_str(&message);
let mut deserializer = serde_json::Deserializer::from_str(&message); deserializer.disable_recursion_limit();
deserializer.disable_recursion_limit(); if let Ok(message) = JsonMessage::deserialize(&mut deserializer) {
if let Ok(message) = cargo_metadata::Message::deserialize(&mut deserializer) { match message {
// Skip certain kinds of messages to only spend time on what's useful // Skip certain kinds of messages to only spend time on what's useful
match message { JsonMessage::Cargo(message) => match message {
cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => { cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => {
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap() self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap()
} }
@ -338,18 +338,12 @@ impl CargoActor {
| cargo_metadata::Message::BuildFinished(_) | cargo_metadata::Message::BuildFinished(_)
| cargo_metadata::Message::TextLine(_) | cargo_metadata::Message::TextLine(_)
| _ => (), | _ => (),
},
JsonMessage::Rustc(message) => {
self.sender.send(CargoMessage::Diagnostic(message)).unwrap()
} }
} }
} }
// Try to deserialize a Diagnostic directly from Rustc.
{
let mut deserializer = serde_json::Deserializer::from_str(&message);
deserializer.disable_recursion_limit();
if let Ok(message) = Diagnostic::deserialize(&mut deserializer) {
self.sender.send(CargoMessage::Diagnostic(message)).unwrap()
}
}
} }
Ok(read_at_least_one_message) Ok(read_at_least_one_message)
} }
@ -359,3 +353,10 @@ enum CargoMessage {
CompilerArtifact(cargo_metadata::Artifact), CompilerArtifact(cargo_metadata::Artifact),
Diagnostic(Diagnostic), Diagnostic(Diagnostic),
} }
#[derive(Deserialize)]
#[serde(untagged)]
enum JsonMessage {
Cargo(cargo_metadata::Message),
Rustc(Diagnostic),
}