@@ -2069,7 +2069,8 @@ fn collect_print_requests(
20692069 check_print_request_stability ( early_dcx, unstable_opts, ( print_name, * print_kind) ) ;
20702070 * print_kind
20712071 } else {
2072- emit_unknown_print_request_help ( early_dcx, req)
2072+ let is_nightly = nightly_options:: match_is_nightly_build ( matches) ;
2073+ emit_unknown_print_request_help ( early_dcx, req, is_nightly)
20732074 } ;
20742075
20752076 let out = out. unwrap_or ( OutFileName :: Stdout ) ;
@@ -2093,25 +2094,37 @@ fn check_print_request_stability(
20932094 unstable_opts : & UnstableOptions ,
20942095 ( print_name, print_kind) : ( & str , PrintKind ) ,
20952096) {
2097+ if !is_print_request_stability ( print_kind) && !unstable_opts. unstable_options {
2098+ early_dcx. early_fatal ( format ! (
2099+ "the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2100+ print option"
2101+ ) ) ;
2102+ }
2103+ }
2104+
2105+ fn is_print_request_stability ( print_kind : PrintKind ) -> bool {
20962106 match print_kind {
20972107 PrintKind :: AllTargetSpecsJson
20982108 | PrintKind :: CheckCfg
20992109 | PrintKind :: CrateRootLintLevels
21002110 | PrintKind :: SupportedCrateTypes
2101- | PrintKind :: TargetSpecJson
2102- if !unstable_opts. unstable_options =>
2103- {
2104- early_dcx. early_fatal ( format ! (
2105- "the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2106- print option"
2107- ) ) ;
2108- }
2109- _ => { }
2111+ | PrintKind :: TargetSpecJson => false ,
2112+ _ => true ,
21102113 }
21112114}
21122115
2113- fn emit_unknown_print_request_help ( early_dcx : & EarlyDiagCtxt , req : & str ) -> ! {
2114- let prints = PRINT_KINDS . iter ( ) . map ( |( name, _) | format ! ( "`{name}`" ) ) . collect :: < Vec < _ > > ( ) ;
2116+ fn emit_unknown_print_request_help ( early_dcx : & EarlyDiagCtxt , req : & str , is_nightly : bool ) -> ! {
2117+ let prints = PRINT_KINDS
2118+ . iter ( )
2119+ . filter_map ( |( name, kind) | {
2120+ // If we're not on nightly, we don't want to print unstable options
2121+ if !is_nightly && !is_print_request_stability ( * kind) {
2122+ None
2123+ } else {
2124+ Some ( format ! ( "`{name}`" ) )
2125+ }
2126+ } )
2127+ . collect :: < Vec < _ > > ( ) ;
21152128 let prints = prints. join ( ", " ) ;
21162129
21172130 let mut diag = early_dcx. early_struct_fatal ( format ! ( "unknown print request: `{req}`" ) ) ;
0 commit comments