@@ -319,13 +319,13 @@ impl CargoActor {
319319
320320 read_at_least_one_message = true ;
321321
322- // Try to deserialize a message from Cargo.
323- {
324- let mut deserializer = serde_json :: Deserializer :: from_str ( & message ) ;
325- deserializer . disable_recursion_limit ( ) ;
326- if let Ok ( message) = cargo_metadata :: Message :: deserialize ( & mut deserializer ) {
322+ // Try to deserialize a message from Cargo or Rustc .
323+ let mut deserializer = serde_json :: Deserializer :: from_str ( & message ) ;
324+ deserializer. disable_recursion_limit ( ) ;
325+ if let Ok ( message ) = JsonMessage :: deserialize ( & mut deserializer ) {
326+ match message {
327327 // Skip certain kinds of messages to only spend time on what's useful
328- match message {
328+ JsonMessage :: Cargo ( message ) => match message {
329329 cargo_metadata:: Message :: CompilerArtifact ( artifact) if !artifact. fresh => {
330330 self . sender . send ( CargoMessage :: CompilerArtifact ( artifact) ) . unwrap ( )
331331 }
@@ -338,18 +338,12 @@ impl CargoActor {
338338 | cargo_metadata:: Message :: BuildFinished ( _)
339339 | cargo_metadata:: Message :: TextLine ( _)
340340 | _ => ( ) ,
341+ } ,
342+ JsonMessage :: Rustc ( message) => {
343+ self . sender . send ( CargoMessage :: Diagnostic ( message) ) . unwrap ( )
341344 }
342345 }
343346 }
344-
345- // Try to deserialize a Diagnostic directly from Rustc.
346- {
347- let mut deserializer = serde_json:: Deserializer :: from_str ( & message) ;
348- deserializer. disable_recursion_limit ( ) ;
349- if let Ok ( message) = Diagnostic :: deserialize ( & mut deserializer) {
350- self . sender . send ( CargoMessage :: Diagnostic ( message) ) . unwrap ( )
351- }
352- }
353347 }
354348 Ok ( read_at_least_one_message)
355349 }
@@ -359,3 +353,10 @@ enum CargoMessage {
359353 CompilerArtifact ( cargo_metadata:: Artifact ) ,
360354 Diagnostic ( Diagnostic ) ,
361355}
356+
357+ #[ derive( Deserialize ) ]
358+ #[ serde( untagged) ]
359+ enum JsonMessage {
360+ Cargo ( cargo_metadata:: Message ) ,
361+ Rustc ( Diagnostic ) ,
362+ }
0 commit comments