@@ -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 { short : false } ;
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 ;
@@ -2068,7 +2076,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20682076 for sub_option in option. split ( ',' ) {
20692077 match sub_option {
20702078 "diagnostic-short" => {
2071- json_rendered = HumanReadableErrorType :: Default { short : true }
2079+ json_rendered = if is_nightly_build {
2080+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2081+ } else {
2082+ HumanReadableErrorType :: Default { short : true }
2083+ } ;
20722084 }
20732085 "diagnostic-unicode" => {
20742086 json_rendered =
@@ -2102,14 +2114,22 @@ pub fn parse_error_format(
21022114 color_config : ColorConfig ,
21032115 json_color : ColorConfig ,
21042116 json_rendered : HumanReadableErrorType ,
2117+ is_nightly_build : bool ,
21052118) -> ErrorOutputType {
2119+ let default_kind = if is_nightly_build {
2120+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2121+ } else {
2122+ HumanReadableErrorType :: Default { short : false }
2123+ } ;
21062124 // We need the `opts_present` check because the driver will send us Matches
21072125 // with only stable options if no unstable options are used. Since error-format
21082126 // is unstable, it will not be present. We have to use `opts_present` not
21092127 // `opt_present` because the latter will panic.
21102128 let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
21112129 match matches. opt_str ( "error-format" ) . as_deref ( ) {
2112- None | Some ( "human" ) => ErrorOutputType :: HumanReadable { color_config, .. } ,
2130+ None | Some ( "human" ) => {
2131+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
2132+ }
21132133 Some ( "human-annotate-rs" ) => ErrorOutputType :: HumanReadable {
21142134 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false } ,
21152135 color_config,
@@ -2121,23 +2141,30 @@ pub fn parse_error_format(
21212141 ErrorOutputType :: Json { pretty : true , json_rendered, color_config : json_color }
21222142 }
21232143 Some ( "short" ) => ErrorOutputType :: HumanReadable {
2124- kind : HumanReadableErrorType :: Default { short : true } ,
2144+ kind : if is_nightly_build {
2145+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2146+ } else {
2147+ HumanReadableErrorType :: Default { short : true }
2148+ } ,
21252149 color_config,
21262150 } ,
21272151 Some ( "human-unicode" ) => ErrorOutputType :: HumanReadable {
21282152 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : true } ,
21292153 color_config,
21302154 } ,
21312155 Some ( arg) => {
2132- 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+ } ) ;
21332160 early_dcx. early_fatal ( format ! (
21342161 "argument for `--error-format` must be `human`, `human-annotate-rs`, \
21352162 `human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21362163 ) )
21372164 }
21382165 }
21392166 } else {
2140- ErrorOutputType :: HumanReadable { color_config, .. }
2167+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
21412168 } ;
21422169
21432170 match error_format {
@@ -2185,9 +2212,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21852212fn check_error_format_stability (
21862213 early_dcx : & EarlyDiagCtxt ,
21872214 unstable_opts : & UnstableOptions ,
2215+ is_nightly_build : bool ,
21882216 format : ErrorOutputType ,
21892217) {
2190- if unstable_opts. unstable_options {
2218+ if unstable_opts. unstable_options || is_nightly_build {
21912219 return ;
21922220 }
21932221 let format = match format {
@@ -2615,16 +2643,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26152643
26162644 let edition = parse_crate_edition ( early_dcx, matches) ;
26172645
2646+ let crate_name = matches. opt_str ( "crate-name" ) ;
2647+ let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
26182648 let JsonConfig {
26192649 json_rendered,
26202650 json_color,
26212651 json_artifact_notifications,
26222652 json_timings,
26232653 json_unused_externs,
26242654 json_future_incompat,
2625- } = parse_json ( early_dcx, matches) ;
2655+ } = parse_json ( early_dcx, matches, unstable_features . is_nightly_build ( ) ) ;
26262656
2627- 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+ ) ;
26282665
26292666 early_dcx. set_error_format ( error_format) ;
26302667
@@ -2645,7 +2682,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26452682 early_dcx. early_fatal ( "--json=timings is unstable and requires using `-Zunstable-options`" ) ;
26462683 }
26472684
2648- 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+ ) ;
26492691
26502692 let output_types = parse_output_types ( early_dcx, & unstable_opts, matches) ;
26512693
@@ -2832,8 +2874,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28322874 )
28332875 }
28342876
2835- let crate_name = matches. opt_str ( "crate-name" ) ;
2836- let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
28372877 // Parse any `-l` flags, which link to native libraries.
28382878 let libs = parse_native_libs ( early_dcx, & unstable_opts, unstable_features, matches) ;
28392879
0 commit comments