@@ -602,20 +602,21 @@ impl OutputType {
602602#[ derive( Clone ,  Copy ,  Debug ,  PartialEq ,  Eq ) ]  
603603pub  enum  ErrorOutputType  { 
604604    /// Output meant for the consumption of humans. 
605-      HumanReadable ( HumanReadableErrorType ) , 
605+      HumanReadable ( HumanReadableErrorType ,   ColorConfig ) , 
606606    /// Output that's consumed by other tools such as `rustfix` or the `RLS`. 
607607     Json  { 
608608        /// Render the JSON in a human readable way (with indents and newlines). 
609609         pretty :  bool , 
610610        /// The JSON output includes a `rendered` field that includes the rendered 
611611         /// human output. 
612612         json_rendered :  HumanReadableErrorType , 
613+         color_config :  ColorConfig , 
613614    } , 
614615} 
615616
616617impl  Default  for  ErrorOutputType  { 
617618    fn  default ( )  -> Self  { 
618-         Self :: HumanReadable ( HumanReadableErrorType :: Default ( ColorConfig :: Auto ) ) 
619+         Self :: HumanReadable ( HumanReadableErrorType :: Default ,   ColorConfig :: Auto ) 
619620    } 
620621} 
621622
@@ -1631,6 +1632,7 @@ pub fn parse_color(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Col
16311632/// Possible json config files 
16321633pub  struct  JsonConfig  { 
16331634    pub  json_rendered :  HumanReadableErrorType , 
1635+     pub  json_color :  ColorConfig , 
16341636    json_artifact_notifications :  bool , 
16351637    pub  json_unused_externs :  JsonUnusedExterns , 
16361638    json_future_incompat :  bool , 
@@ -1668,8 +1670,7 @@ impl JsonUnusedExterns {
16681670/// The first value returned is how to render JSON diagnostics, and the second 
16691671/// is whether or not artifact notifications are enabled. 
16701672pub  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 ; 
16731674    let  mut  json_color = ColorConfig :: Never ; 
16741675    let  mut  json_artifact_notifications = false ; 
16751676    let  mut  json_unused_externs = JsonUnusedExterns :: No ; 
@@ -1696,7 +1697,8 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
16961697    } 
16971698
16981699    JsonConfig  { 
1699-         json_rendered :  json_rendered ( json_color) , 
1700+         json_rendered, 
1701+         json_color, 
17001702        json_artifact_notifications, 
17011703        json_unused_externs, 
17021704        json_future_incompat, 
@@ -1708,6 +1710,7 @@ pub fn parse_error_format(
17081710    early_dcx :  & mut  EarlyDiagCtxt , 
17091711    matches :  & getopts:: Matches , 
17101712    color :  ColorConfig , 
1713+     json_color :  ColorConfig , 
17111714    json_rendered :  HumanReadableErrorType , 
17121715)  -> ErrorOutputType  { 
17131716    // We need the `opts_present` check because the driver will send us Matches 
@@ -1717,18 +1720,22 @@ pub fn parse_error_format(
17171720    let  error_format = if  matches. opts_present ( & [ "error-format" . to_owned ( ) ] )  { 
17181721        match  matches. opt_str ( "error-format" ) . as_deref ( )  { 
17191722            None  | Some ( "human" )  => { 
1720-                 ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) ) 
1723+                 ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ,   color) 
17211724            } 
17221725            Some ( "human-annotate-rs" )  => { 
1723-                 ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ( color) ) 
1726+                 ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ,   color) 
17241727            } 
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) , 
17291735            Some ( arg)  => { 
17301736                early_dcx. abort_if_error_and_set_error_format ( ErrorOutputType :: HumanReadable ( 
1731-                     HumanReadableErrorType :: Default ( color) , 
1737+                     HumanReadableErrorType :: Default , 
1738+                     color, 
17321739                ) ) ; 
17331740                early_dcx. early_fatal ( format ! ( 
17341741                    "argument for `--error-format` must be `human`, `json` or \  
@@ -1737,7 +1744,7 @@ pub fn parse_error_format(
17371744            } 
17381745        } 
17391746    }  else  { 
1740-         ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( color) ) 
1747+         ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ,   color) 
17411748    } ; 
17421749
17431750    match  error_format { 
@@ -1791,7 +1798,7 @@ fn check_error_format_stability(
17911798        if  let  ErrorOutputType :: Json  {  pretty :  true ,  .. }  = error_format { 
17921799            early_dcx. early_fatal ( "`--error-format=pretty-json` is unstable" ) ; 
17931800        } 
1794-         if  let  ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ( _ ) )  =
1801+         if  let  ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: AnnotateSnippet ,  _ )  =
17951802            error_format
17961803        { 
17971804            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
23922399
23932400    let  JsonConfig  { 
23942401        json_rendered, 
2402+         json_color, 
23952403        json_artifact_notifications, 
23962404        json_unused_externs, 
23972405        json_future_incompat, 
23982406    }  = parse_json ( early_dcx,  matches) ; 
23992407
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) ; 
24012409
24022410    early_dcx. abort_if_error_and_set_error_format ( error_format) ; 
24032411
0 commit comments