@@ -2041,8 +2041,16 @@ impl JsonUnusedExterns {
20412041///
20422042/// The first value returned is how to render JSON diagnostics, and the second
20432043/// is whether or not artifact notifications are enabled.
2044- pub fn parse_json ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> JsonConfig {
2045- let mut json_rendered = HumanReadableErrorType :: Default { short : false } ;
2044+ pub fn parse_json (
2045+ early_dcx : & EarlyDiagCtxt ,
2046+ matches : & getopts:: Matches ,
2047+ is_nightly_build : bool ,
2048+ ) -> JsonConfig {
2049+ let mut json_rendered = if is_nightly_build {
2050+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2051+ } else {
2052+ HumanReadableErrorType :: Default { short : false }
2053+ } ;
20462054 let mut json_color = ColorConfig :: Never ;
20472055 let mut json_artifact_notifications = false ;
20482056 let mut json_unused_externs = JsonUnusedExterns :: No ;
@@ -2059,7 +2067,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20592067 for sub_option in option. split ( ',' ) {
20602068 match sub_option {
20612069 "diagnostic-short" => {
2062- json_rendered = HumanReadableErrorType :: Default { short : true }
2070+ json_rendered = if is_nightly_build {
2071+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2072+ } else {
2073+ HumanReadableErrorType :: Default { short : true }
2074+ } ;
20632075 }
20642076 "diagnostic-unicode" => {
20652077 json_rendered =
@@ -2093,14 +2105,22 @@ pub fn parse_error_format(
20932105 color_config : ColorConfig ,
20942106 json_color : ColorConfig ,
20952107 json_rendered : HumanReadableErrorType ,
2108+ is_nightly_build : bool ,
20962109) -> ErrorOutputType {
2110+ let default_kind = if is_nightly_build {
2111+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2112+ } else {
2113+ HumanReadableErrorType :: Default { short : false }
2114+ } ;
20972115 // We need the `opts_present` check because the driver will send us Matches
20982116 // with only stable options if no unstable options are used. Since error-format
20992117 // is unstable, it will not be present. We have to use `opts_present` not
21002118 // `opt_present` because the latter will panic.
21012119 let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
21022120 match matches. opt_str ( "error-format" ) . as_deref ( ) {
2103- None | Some ( "human" ) => ErrorOutputType :: HumanReadable { color_config, .. } ,
2121+ None | Some ( "human" ) => {
2122+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
2123+ }
21042124 Some ( "human-annotate-rs" ) => ErrorOutputType :: HumanReadable {
21052125 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false } ,
21062126 color_config,
@@ -2112,23 +2132,30 @@ pub fn parse_error_format(
21122132 ErrorOutputType :: Json { pretty : true , json_rendered, color_config : json_color }
21132133 }
21142134 Some ( "short" ) => ErrorOutputType :: HumanReadable {
2115- kind : HumanReadableErrorType :: Default { short : true } ,
2135+ kind : if is_nightly_build {
2136+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2137+ } else {
2138+ HumanReadableErrorType :: Default { short : true }
2139+ } ,
21162140 color_config,
21172141 } ,
21182142 Some ( "human-unicode" ) => ErrorOutputType :: HumanReadable {
21192143 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : true } ,
21202144 color_config,
21212145 } ,
21222146 Some ( arg) => {
2123- early_dcx. set_error_format ( ErrorOutputType :: HumanReadable { color_config, .. } ) ;
2147+ early_dcx. set_error_format ( ErrorOutputType :: HumanReadable {
2148+ color_config,
2149+ kind : default_kind,
2150+ } ) ;
21242151 early_dcx. early_fatal ( format ! (
21252152 "argument for `--error-format` must be `human`, `human-annotate-rs`, \
21262153 `human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21272154 ) )
21282155 }
21292156 }
21302157 } else {
2131- ErrorOutputType :: HumanReadable { color_config, .. }
2158+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
21322159 } ;
21332160
21342161 match error_format {
@@ -2176,9 +2203,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21762203fn check_error_format_stability (
21772204 early_dcx : & EarlyDiagCtxt ,
21782205 unstable_opts : & UnstableOptions ,
2206+ is_nightly_build : bool ,
21792207 format : ErrorOutputType ,
21802208) {
2181- if unstable_opts. unstable_options {
2209+ if unstable_opts. unstable_options || is_nightly_build {
21822210 return ;
21832211 }
21842212 let format = match format {
@@ -2606,16 +2634,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26062634
26072635 let edition = parse_crate_edition ( early_dcx, matches) ;
26082636
2637+ let crate_name = matches. opt_str ( "crate-name" ) ;
2638+ let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
26092639 let JsonConfig {
26102640 json_rendered,
26112641 json_color,
26122642 json_artifact_notifications,
26132643 json_timings,
26142644 json_unused_externs,
26152645 json_future_incompat,
2616- } = parse_json ( early_dcx, matches) ;
2646+ } = parse_json ( early_dcx, matches, unstable_features . is_nightly_build ( ) ) ;
26172647
2618- let error_format = parse_error_format ( early_dcx, matches, color, json_color, json_rendered) ;
2648+ let error_format = parse_error_format (
2649+ early_dcx,
2650+ matches,
2651+ color,
2652+ json_color,
2653+ json_rendered,
2654+ unstable_features. is_nightly_build ( ) ,
2655+ ) ;
26192656
26202657 early_dcx. set_error_format ( error_format) ;
26212658
@@ -2636,7 +2673,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26362673 early_dcx. early_fatal ( "--json=timings is unstable and requires using `-Zunstable-options`" ) ;
26372674 }
26382675
2639- check_error_format_stability ( early_dcx, & unstable_opts, error_format) ;
2676+ check_error_format_stability (
2677+ early_dcx,
2678+ & unstable_opts,
2679+ unstable_features. is_nightly_build ( ) ,
2680+ error_format,
2681+ ) ;
26402682
26412683 let output_types = parse_output_types ( early_dcx, & unstable_opts, matches) ;
26422684
@@ -2823,8 +2865,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28232865 )
28242866 }
28252867
2826- let crate_name = matches. opt_str ( "crate-name" ) ;
2827- let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
28282868 // Parse any `-l` flags, which link to native libraries.
28292869 let libs = parse_native_libs ( early_dcx, & unstable_opts, unstable_features, matches) ;
28302870
0 commit comments