@@ -602,20 +602,21 @@ impl OutputType {
602
602
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
603
603
pub enum ErrorOutputType {
604
604
/// Output meant for the consumption of humans.
605
- HumanReadable ( HumanReadableErrorType ) ,
605
+ HumanReadable ( HumanReadableErrorType , ColorConfig ) ,
606
606
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
607
607
Json {
608
608
/// Render the JSON in a human readable way (with indents and newlines).
609
609
pretty : bool ,
610
610
/// The JSON output includes a `rendered` field that includes the rendered
611
611
/// human output.
612
612
json_rendered : HumanReadableErrorType ,
613
+ color_config : ColorConfig ,
613
614
} ,
614
615
}
615
616
616
617
impl Default for ErrorOutputType {
617
618
fn default ( ) -> Self {
618
- Self :: HumanReadable ( HumanReadableErrorType :: Default ( ColorConfig :: Auto ) )
619
+ Self :: HumanReadable ( HumanReadableErrorType :: Default , ColorConfig :: Auto )
619
620
}
620
621
}
621
622
@@ -1631,6 +1632,7 @@ pub fn parse_color(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Col
1631
1632
/// Possible json config files
1632
1633
pub struct JsonConfig {
1633
1634
pub json_rendered : HumanReadableErrorType ,
1635
+ pub json_color : ColorConfig ,
1634
1636
json_artifact_notifications : bool ,
1635
1637
pub json_unused_externs : JsonUnusedExterns ,
1636
1638
json_future_incompat : bool ,
@@ -1668,8 +1670,7 @@ impl JsonUnusedExterns {
1668
1670
/// The first value returned is how to render JSON diagnostics, and the second
1669
1671
/// is whether or not artifact notifications are enabled.
1670
1672
pub fn parse_json ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> JsonConfig {
1671
- let mut json_rendered: fn ( ColorConfig ) -> HumanReadableErrorType =
1672
- HumanReadableErrorType :: Default ;
1673
+ let mut json_rendered = HumanReadableErrorType :: Default ;
1673
1674
let mut json_color = ColorConfig :: Never ;
1674
1675
let mut json_artifact_notifications = false ;
1675
1676
let mut json_unused_externs = JsonUnusedExterns :: No ;
@@ -1696,7 +1697,8 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
1696
1697
}
1697
1698
1698
1699
JsonConfig {
1699
- json_rendered : json_rendered ( json_color) ,
1700
+ json_rendered,
1701
+ json_color,
1700
1702
json_artifact_notifications,
1701
1703
json_unused_externs,
1702
1704
json_future_incompat,
@@ -1708,6 +1710,7 @@ pub fn parse_error_format(
1708
1710
early_dcx : & mut EarlyDiagCtxt ,
1709
1711
matches : & getopts:: Matches ,
1710
1712
color : ColorConfig ,
1713
+ json_color : ColorConfig ,
1711
1714
json_rendered : HumanReadableErrorType ,
1712
1715
) -> ErrorOutputType {
1713
1716
// We need the `opts_present` check because the driver will send us Matches
@@ -1717,18 +1720,22 @@ pub fn parse_error_format(
1717
1720
let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
1718
1721
match matches. opt_str ( "error-format" ) . as_deref ( ) {
1719
1722
None | Some ( "human" ) => {
1720
- ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) )
1723
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default , color)
1721
1724
}
1722
1725
Some ( "human-annotate-rs" ) => {
1723
- ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ( color) )
1726
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet , color)
1724
1727
}
1725
- Some ( "json" ) => ErrorOutputType :: Json { pretty : false , json_rendered } ,
1726
- Some ( "pretty-json" ) => ErrorOutputType :: Json { pretty : true , json_rendered } ,
1727
- Some ( "short" ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Short ( color) ) ,
1728
-
1728
+ Some ( "json" ) => {
1729
+ ErrorOutputType :: Json { pretty : false , json_rendered, color_config : json_color }
1730
+ }
1731
+ Some ( "pretty-json" ) => {
1732
+ ErrorOutputType :: Json { pretty : true , json_rendered, color_config : json_color }
1733
+ }
1734
+ Some ( "short" ) => ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Short , color) ,
1729
1735
Some ( arg) => {
1730
1736
early_dcx. abort_if_error_and_set_error_format ( ErrorOutputType :: HumanReadable (
1731
- HumanReadableErrorType :: Default ( color) ,
1737
+ HumanReadableErrorType :: Default ,
1738
+ color,
1732
1739
) ) ;
1733
1740
early_dcx. early_fatal ( format ! (
1734
1741
"argument for `--error-format` must be `human`, `json` or \
@@ -1737,7 +1744,7 @@ pub fn parse_error_format(
1737
1744
}
1738
1745
}
1739
1746
} else {
1740
- ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) )
1747
+ ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default , color)
1741
1748
} ;
1742
1749
1743
1750
match error_format {
@@ -1791,7 +1798,7 @@ fn check_error_format_stability(
1791
1798
if let ErrorOutputType :: Json { pretty : true , .. } = error_format {
1792
1799
early_dcx. early_fatal ( "`--error-format=pretty-json` is unstable" ) ;
1793
1800
}
1794
- if let ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ( _ ) ) =
1801
+ if let ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet , _ ) =
1795
1802
error_format
1796
1803
{
1797
1804
early_dcx. early_fatal ( "`--error-format=human-annotate-rs` is unstable" ) ;
@@ -2392,12 +2399,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2392
2399
2393
2400
let JsonConfig {
2394
2401
json_rendered,
2402
+ json_color,
2395
2403
json_artifact_notifications,
2396
2404
json_unused_externs,
2397
2405
json_future_incompat,
2398
2406
} = parse_json ( early_dcx, matches) ;
2399
2407
2400
- let error_format = parse_error_format ( early_dcx, matches, color, json_rendered) ;
2408
+ let error_format = parse_error_format ( early_dcx, matches, color, json_color , json_rendered) ;
2401
2409
2402
2410
early_dcx. abort_if_error_and_set_error_format ( error_format) ;
2403
2411
0 commit comments