@@ -837,7 +837,7 @@ pub enum ErrorOutputType {
837837 /// Output meant for the consumption of humans.
838838 #[ default]
839839 HumanReadable {
840- kind : HumanReadableErrorType = HumanReadableErrorType :: Default ,
840+ kind : HumanReadableErrorType = HumanReadableErrorType :: Default { short : false } ,
841841 color_config: ColorConfig = ColorConfig :: Auto ,
842842 } ,
843843 /// Output that's consumed by other tools such as `rustfix` or the `RLS`.
@@ -2050,8 +2050,16 @@ impl JsonUnusedExterns {
20502050///
20512051/// The first value returned is how to render JSON diagnostics, and the second
20522052/// is whether or not artifact notifications are enabled.
2053- pub fn parse_json ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> JsonConfig {
2054- let mut json_rendered = HumanReadableErrorType :: Default ;
2053+ pub fn parse_json (
2054+ early_dcx : & EarlyDiagCtxt ,
2055+ matches : & getopts:: Matches ,
2056+ is_nightly_build : bool ,
2057+ ) -> JsonConfig {
2058+ let mut json_rendered = if is_nightly_build {
2059+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2060+ } else {
2061+ HumanReadableErrorType :: Default { short : false }
2062+ } ;
20552063 let mut json_color = ColorConfig :: Never ;
20562064 let mut json_artifact_notifications = false ;
20572065 let mut json_unused_externs = JsonUnusedExterns :: No ;
@@ -2067,9 +2075,16 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20672075
20682076 for sub_option in option. split ( ',' ) {
20692077 match sub_option {
2070- "diagnostic-short" => json_rendered = HumanReadableErrorType :: Short ,
2078+ "diagnostic-short" => {
2079+ json_rendered = if is_nightly_build {
2080+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2081+ } else {
2082+ HumanReadableErrorType :: Default { short : true }
2083+ } ;
2084+ }
20712085 "diagnostic-unicode" => {
2072- json_rendered = HumanReadableErrorType :: Unicode ;
2086+ json_rendered =
2087+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : true } ;
20732088 }
20742089 "diagnostic-rendered-ansi" => json_color = ColorConfig :: Always ,
20752090 "artifacts" => json_artifact_notifications = true ,
@@ -2099,16 +2114,24 @@ pub fn parse_error_format(
20992114 color_config : ColorConfig ,
21002115 json_color : ColorConfig ,
21012116 json_rendered : HumanReadableErrorType ,
2117+ is_nightly_build : bool ,
21022118) -> ErrorOutputType {
2119+ let default_kind = if is_nightly_build {
2120+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2121+ } else {
2122+ HumanReadableErrorType :: Default { short : false }
2123+ } ;
21032124 // We need the `opts_present` check because the driver will send us Matches
21042125 // with only stable options if no unstable options are used. Since error-format
21052126 // is unstable, it will not be present. We have to use `opts_present` not
21062127 // `opt_present` because the latter will panic.
21072128 let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
21082129 match matches. opt_str ( "error-format" ) . as_deref ( ) {
2109- None | Some ( "human" ) => ErrorOutputType :: HumanReadable { color_config, .. } ,
2130+ None | Some ( "human" ) => {
2131+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
2132+ }
21102133 Some ( "human-annotate-rs" ) => ErrorOutputType :: HumanReadable {
2111- kind : HumanReadableErrorType :: AnnotateSnippet ,
2134+ kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false } ,
21122135 color_config,
21132136 } ,
21142137 Some ( "json" ) => {
@@ -2117,23 +2140,31 @@ pub fn parse_error_format(
21172140 Some ( "pretty-json" ) => {
21182141 ErrorOutputType :: Json { pretty : true , json_rendered, color_config : json_color }
21192142 }
2120- Some ( "short" ) => {
2121- ErrorOutputType :: HumanReadable { kind : HumanReadableErrorType :: Short , color_config }
2122- }
2143+ Some ( "short" ) => ErrorOutputType :: HumanReadable {
2144+ kind : if is_nightly_build {
2145+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2146+ } else {
2147+ HumanReadableErrorType :: Default { short : true }
2148+ } ,
2149+ color_config,
2150+ } ,
21232151 Some ( "human-unicode" ) => ErrorOutputType :: HumanReadable {
2124- kind : HumanReadableErrorType :: Unicode ,
2152+ kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : true } ,
21252153 color_config,
21262154 } ,
21272155 Some ( arg) => {
2128- early_dcx. set_error_format ( ErrorOutputType :: HumanReadable { color_config, .. } ) ;
2156+ early_dcx. set_error_format ( ErrorOutputType :: HumanReadable {
2157+ color_config,
2158+ kind : default_kind,
2159+ } ) ;
21292160 early_dcx. early_fatal ( format ! (
21302161 "argument for `--error-format` must be `human`, `human-annotate-rs`, \
21312162 `human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21322163 ) )
21332164 }
21342165 }
21352166 } else {
2136- ErrorOutputType :: HumanReadable { color_config, .. }
2167+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
21372168 } ;
21382169
21392170 match error_format {
@@ -2181,16 +2212,17 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21812212fn check_error_format_stability (
21822213 early_dcx : & EarlyDiagCtxt ,
21832214 unstable_opts : & UnstableOptions ,
2215+ is_nightly_build : bool ,
21842216 format : ErrorOutputType ,
21852217) {
2186- if unstable_opts. unstable_options {
2218+ if unstable_opts. unstable_options || is_nightly_build {
21872219 return ;
21882220 }
21892221 let format = match format {
21902222 ErrorOutputType :: Json { pretty : true , .. } => "pretty-json" ,
21912223 ErrorOutputType :: HumanReadable { kind, .. } => match kind {
2192- HumanReadableErrorType :: AnnotateSnippet => "human-annotate-rs" ,
2193- HumanReadableErrorType :: Unicode => "human-unicode" ,
2224+ HumanReadableErrorType :: AnnotateSnippet { unicode : false , .. } => "human-annotate-rs" ,
2225+ HumanReadableErrorType :: AnnotateSnippet { unicode : true , .. } => "human-unicode" ,
21942226 _ => return ,
21952227 } ,
21962228 _ => return ,
@@ -2611,16 +2643,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26112643
26122644 let edition = parse_crate_edition ( early_dcx, matches) ;
26132645
2646+ let crate_name = matches. opt_str ( "crate-name" ) ;
2647+ let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
26142648 let JsonConfig {
26152649 json_rendered,
26162650 json_color,
26172651 json_artifact_notifications,
26182652 json_timings,
26192653 json_unused_externs,
26202654 json_future_incompat,
2621- } = parse_json ( early_dcx, matches) ;
2655+ } = parse_json ( early_dcx, matches, unstable_features . is_nightly_build ( ) ) ;
26222656
2623- let error_format = parse_error_format ( early_dcx, matches, color, json_color, json_rendered) ;
2657+ let error_format = parse_error_format (
2658+ early_dcx,
2659+ matches,
2660+ color,
2661+ json_color,
2662+ json_rendered,
2663+ unstable_features. is_nightly_build ( ) ,
2664+ ) ;
26242665
26252666 early_dcx. set_error_format ( error_format) ;
26262667
@@ -2641,7 +2682,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26412682 early_dcx. early_fatal ( "--json=timings is unstable and requires using `-Zunstable-options`" ) ;
26422683 }
26432684
2644- check_error_format_stability ( early_dcx, & unstable_opts, error_format) ;
2685+ check_error_format_stability (
2686+ early_dcx,
2687+ & unstable_opts,
2688+ unstable_features. is_nightly_build ( ) ,
2689+ error_format,
2690+ ) ;
26452691
26462692 let output_types = parse_output_types ( early_dcx, & unstable_opts, matches) ;
26472693
@@ -2828,8 +2874,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28282874 )
28292875 }
28302876
2831- let crate_name = matches. opt_str ( "crate-name" ) ;
2832- let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
28332877 // Parse any `-l` flags, which link to native libraries.
28342878 let libs = parse_native_libs ( early_dcx, & unstable_opts, unstable_features, matches) ;
28352879
0 commit comments