@@ -2052,8 +2052,16 @@ impl JsonUnusedExterns {
20522052///
20532053/// The first value returned is how to render JSON diagnostics, and the second
20542054/// is whether or not artifact notifications are enabled.
2055- pub fn parse_json ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> JsonConfig {
2056- let mut json_rendered = HumanReadableErrorType :: Default { short : false } ;
2055+ pub fn parse_json (
2056+ early_dcx : & EarlyDiagCtxt ,
2057+ matches : & getopts:: Matches ,
2058+ is_nightly_build : bool ,
2059+ ) -> JsonConfig {
2060+ let mut json_rendered = if is_nightly_build {
2061+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2062+ } else {
2063+ HumanReadableErrorType :: Default { short : false }
2064+ } ;
20572065 let mut json_color = ColorConfig :: Never ;
20582066 let mut json_artifact_notifications = false ;
20592067 let mut json_unused_externs = JsonUnusedExterns :: No ;
@@ -2070,7 +2078,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20702078 for sub_option in option. split ( ',' ) {
20712079 match sub_option {
20722080 "diagnostic-short" => {
2073- json_rendered = HumanReadableErrorType :: Default { short : true }
2081+ json_rendered = if is_nightly_build {
2082+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2083+ } else {
2084+ HumanReadableErrorType :: Default { short : true }
2085+ } ;
20742086 }
20752087 "diagnostic-unicode" => {
20762088 json_rendered =
@@ -2104,14 +2116,22 @@ pub fn parse_error_format(
21042116 color_config : ColorConfig ,
21052117 json_color : ColorConfig ,
21062118 json_rendered : HumanReadableErrorType ,
2119+ is_nightly_build : bool ,
21072120) -> ErrorOutputType {
2121+ let default_kind = if is_nightly_build {
2122+ HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false }
2123+ } else {
2124+ HumanReadableErrorType :: Default { short : false }
2125+ } ;
21082126 // We need the `opts_present` check because the driver will send us Matches
21092127 // with only stable options if no unstable options are used. Since error-format
21102128 // is unstable, it will not be present. We have to use `opts_present` not
21112129 // `opt_present` because the latter will panic.
21122130 let error_format = if matches. opts_present ( & [ "error-format" . to_owned ( ) ] ) {
21132131 match matches. opt_str ( "error-format" ) . as_deref ( ) {
2114- None | Some ( "human" ) => ErrorOutputType :: HumanReadable { color_config, .. } ,
2132+ None | Some ( "human" ) => {
2133+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
2134+ }
21152135 Some ( "human-annotate-rs" ) => ErrorOutputType :: HumanReadable {
21162136 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : false } ,
21172137 color_config,
@@ -2123,23 +2143,30 @@ pub fn parse_error_format(
21232143 ErrorOutputType :: Json { pretty : true , json_rendered, color_config : json_color }
21242144 }
21252145 Some ( "short" ) => ErrorOutputType :: HumanReadable {
2126- kind : HumanReadableErrorType :: Default { short : true } ,
2146+ kind : if is_nightly_build {
2147+ HumanReadableErrorType :: AnnotateSnippet { short : true , unicode : false }
2148+ } else {
2149+ HumanReadableErrorType :: Default { short : true }
2150+ } ,
21272151 color_config,
21282152 } ,
21292153 Some ( "human-unicode" ) => ErrorOutputType :: HumanReadable {
21302154 kind : HumanReadableErrorType :: AnnotateSnippet { short : false , unicode : true } ,
21312155 color_config,
21322156 } ,
21332157 Some ( arg) => {
2134- early_dcx. set_error_format ( ErrorOutputType :: HumanReadable { color_config, .. } ) ;
2158+ early_dcx. set_error_format ( ErrorOutputType :: HumanReadable {
2159+ color_config,
2160+ kind : default_kind,
2161+ } ) ;
21352162 early_dcx. early_fatal ( format ! (
21362163 "argument for `--error-format` must be `human`, `human-annotate-rs`, \
21372164 `human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21382165 ) )
21392166 }
21402167 }
21412168 } else {
2142- ErrorOutputType :: HumanReadable { color_config, .. }
2169+ ErrorOutputType :: HumanReadable { color_config, kind : default_kind }
21432170 } ;
21442171
21452172 match error_format {
@@ -2187,9 +2214,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21872214fn check_error_format_stability (
21882215 early_dcx : & EarlyDiagCtxt ,
21892216 unstable_opts : & UnstableOptions ,
2217+ is_nightly_build : bool ,
21902218 format : ErrorOutputType ,
21912219) {
2192- if unstable_opts. unstable_options {
2220+ if unstable_opts. unstable_options || is_nightly_build {
21932221 return ;
21942222 }
21952223 let format = match format {
@@ -2617,16 +2645,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26172645
26182646 let edition = parse_crate_edition ( early_dcx, matches) ;
26192647
2648+ let crate_name = matches. opt_str ( "crate-name" ) ;
2649+ let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
26202650 let JsonConfig {
26212651 json_rendered,
26222652 json_color,
26232653 json_artifact_notifications,
26242654 json_timings,
26252655 json_unused_externs,
26262656 json_future_incompat,
2627- } = parse_json ( early_dcx, matches) ;
2657+ } = parse_json ( early_dcx, matches, unstable_features . is_nightly_build ( ) ) ;
26282658
2629- let error_format = parse_error_format ( early_dcx, matches, color, json_color, json_rendered) ;
2659+ let error_format = parse_error_format (
2660+ early_dcx,
2661+ matches,
2662+ color,
2663+ json_color,
2664+ json_rendered,
2665+ unstable_features. is_nightly_build ( ) ,
2666+ ) ;
26302667
26312668 early_dcx. set_error_format ( error_format) ;
26322669
@@ -2647,7 +2684,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26472684 early_dcx. early_fatal ( "--json=timings is unstable and requires using `-Zunstable-options`" ) ;
26482685 }
26492686
2650- check_error_format_stability ( early_dcx, & unstable_opts, error_format) ;
2687+ check_error_format_stability (
2688+ early_dcx,
2689+ & unstable_opts,
2690+ unstable_features. is_nightly_build ( ) ,
2691+ error_format,
2692+ ) ;
26512693
26522694 let output_types = parse_output_types ( early_dcx, & unstable_opts, matches) ;
26532695
@@ -2834,8 +2876,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28342876 )
28352877 }
28362878
2837- let crate_name = matches. opt_str ( "crate-name" ) ;
2838- let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
28392879 // Parse any `-l` flags, which link to native libraries.
28402880 let libs = parse_native_libs ( early_dcx, & unstable_opts, unstable_features, matches) ;
28412881
0 commit comments