@@ -1742,6 +1742,33 @@ fn on_stderr_line_inner(
1742
1742
return Ok ( true ) ;
1743
1743
}
1744
1744
1745
+ #[ derive( serde:: Deserialize ) ]
1746
+ struct CompilerMessage {
1747
+ rendered : String ,
1748
+ message : String ,
1749
+ level : String ,
1750
+ children : Vec < PartialDiagnostic > ,
1751
+ }
1752
+
1753
+ // A partial rustfix::diagnostics::Diagnostic. We deserialize only a
1754
+ // subset of the fields because rustc's output can be extremely
1755
+ // deeply nested JSON in pathological cases involving macro
1756
+ // expansion. Rustfix's Diagnostic struct is recursive containing a
1757
+ // field `children: Vec<Self>`, and it can cause deserialization to
1758
+ // hit serde_json's default recursion limit, or overflow the stack
1759
+ // if we turn that off. Cargo only cares about the 1 field listed
1760
+ // here.
1761
+ #[ derive( serde:: Deserialize ) ]
1762
+ struct PartialDiagnostic {
1763
+ spans : Vec < PartialDiagnosticSpan > ,
1764
+ }
1765
+
1766
+ // A partial rustfix::diagnostics::DiagnosticSpan.
1767
+ #[ derive( serde:: Deserialize ) ]
1768
+ struct PartialDiagnosticSpan {
1769
+ suggestion_applicability : Option < Applicability > ,
1770
+ }
1771
+
1745
1772
// Depending on what we're emitting from Cargo itself, we figure out what to
1746
1773
// do with this JSON message.
1747
1774
match options. format {
@@ -1755,33 +1782,6 @@ fn on_stderr_line_inner(
1755
1782
render_diagnostics : true ,
1756
1783
..
1757
1784
} => {
1758
- #[ derive( serde:: Deserialize ) ]
1759
- struct CompilerMessage {
1760
- rendered : String ,
1761
- message : String ,
1762
- level : String ,
1763
- children : Vec < PartialDiagnostic > ,
1764
- }
1765
-
1766
- // A partial rustfix::diagnostics::Diagnostic. We deserialize only a
1767
- // subset of the fields because rustc's output can be extremely
1768
- // deeply nested JSON in pathological cases involving macro
1769
- // expansion. Rustfix's Diagnostic struct is recursive containing a
1770
- // field `children: Vec<Self>`, and it can cause deserialization to
1771
- // hit serde_json's default recursion limit, or overflow the stack
1772
- // if we turn that off. Cargo only cares about the 1 field listed
1773
- // here.
1774
- #[ derive( serde:: Deserialize ) ]
1775
- struct PartialDiagnostic {
1776
- spans : Vec < PartialDiagnosticSpan > ,
1777
- }
1778
-
1779
- // A partial rustfix::diagnostics::DiagnosticSpan.
1780
- #[ derive( serde:: Deserialize ) ]
1781
- struct PartialDiagnosticSpan {
1782
- suggestion_applicability : Option < Applicability > ,
1783
- }
1784
-
1785
1785
if let Ok ( mut msg) = serde_json:: from_str :: < CompilerMessage > ( compiler_message. get ( ) ) {
1786
1786
if msg. message . starts_with ( "aborting due to" )
1787
1787
|| msg. message . ends_with ( "warning emitted" )
@@ -1865,12 +1865,30 @@ fn on_stderr_line_inner(
1865
1865
return Ok ( true ) ;
1866
1866
}
1867
1867
1868
- #[ derive( serde:: Deserialize ) ]
1869
- struct CompilerMessage {
1870
- level : String ,
1871
- }
1872
- if let Ok ( message) = serde_json:: from_str :: < CompilerMessage > ( compiler_message. get ( ) ) {
1873
- count_diagnostic ( & message. level , options) ;
1868
+ if let Ok ( msg) = serde_json:: from_str :: < CompilerMessage > ( compiler_message. get ( ) ) {
1869
+ if msg. message . starts_with ( "aborting due to" )
1870
+ || msg. message . ends_with ( "warning emitted" )
1871
+ || msg. message . ends_with ( "warnings emitted" )
1872
+ {
1873
+ // Skip this line; we'll print our own summary at the end.
1874
+ return Ok ( true ) ;
1875
+ }
1876
+ let rendered = msg. rendered ;
1877
+ if options. show_diagnostics {
1878
+ let machine_applicable: bool = msg
1879
+ . children
1880
+ . iter ( )
1881
+ . map ( |child| {
1882
+ child
1883
+ . spans
1884
+ . iter ( )
1885
+ . filter_map ( |span| span. suggestion_applicability )
1886
+ . any ( |app| app == Applicability :: MachineApplicable )
1887
+ } )
1888
+ . any ( |b| b) ;
1889
+ count_diagnostic ( & msg. level , options) ;
1890
+ state. emit_diag ( msg. level , rendered, machine_applicable) ?;
1891
+ }
1874
1892
}
1875
1893
1876
1894
let msg = machine_message:: FromCompiler {
0 commit comments