@@ -2032,49 +2032,13 @@ fn collect_print_requests(
2032
2032
prints. extend ( matches. opt_strs ( "print" ) . into_iter ( ) . map ( |req| {
2033
2033
let ( req, out) = split_out_file_name ( & req) ;
2034
2034
2035
- let kind = match PRINT_KINDS . iter ( ) . find ( |& & ( name, _) | name == req) {
2036
- Some ( ( _, PrintKind :: TargetSpec ) ) => {
2037
- if unstable_opts. unstable_options {
2038
- PrintKind :: TargetSpec
2039
- } else {
2040
- early_dcx. early_fatal (
2041
- "the `-Z unstable-options` flag must also be passed to \
2042
- enable the target-spec-json print option",
2043
- ) ;
2044
- }
2045
- }
2046
- Some ( ( _, PrintKind :: AllTargetSpecs ) ) => {
2047
- if unstable_opts. unstable_options {
2048
- PrintKind :: AllTargetSpecs
2049
- } else {
2050
- early_dcx. early_fatal (
2051
- "the `-Z unstable-options` flag must also be passed to \
2052
- enable the all-target-specs-json print option",
2053
- ) ;
2054
- }
2055
- }
2056
- Some ( ( _, PrintKind :: CheckCfg ) ) => {
2057
- if unstable_opts. unstable_options {
2058
- PrintKind :: CheckCfg
2059
- } else {
2060
- early_dcx. early_fatal (
2061
- "the `-Z unstable-options` flag must also be passed to \
2062
- enable the check-cfg print option",
2063
- ) ;
2064
- }
2065
- }
2066
- Some ( & ( _, print_kind) ) => print_kind,
2067
- None => {
2068
- let prints =
2069
- PRINT_KINDS . iter ( ) . map ( |( name, _) | format ! ( "`{name}`" ) ) . collect :: < Vec < _ > > ( ) ;
2070
- let prints = prints. join ( ", " ) ;
2071
-
2072
- let mut diag =
2073
- early_dcx. early_struct_fatal ( format ! ( "unknown print request: `{req}`" ) ) ;
2074
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
2075
- diag. help ( format ! ( "valid print requests are: {prints}" ) ) ;
2076
- diag. emit ( )
2077
- }
2035
+ let kind = if let Some ( ( print_name, print_kind) ) =
2036
+ PRINT_KINDS . iter ( ) . find ( |& & ( name, _) | name == req)
2037
+ {
2038
+ check_print_request_stability ( early_dcx, unstable_opts, ( print_name, * print_kind) ) ;
2039
+ * print_kind
2040
+ } else {
2041
+ emit_unknown_print_request_help ( early_dcx, req)
2078
2042
} ;
2079
2043
2080
2044
let out = out. unwrap_or ( OutFileName :: Stdout ) ;
@@ -2093,6 +2057,34 @@ fn collect_print_requests(
2093
2057
prints
2094
2058
}
2095
2059
2060
+ fn check_print_request_stability (
2061
+ early_dcx : & EarlyDiagCtxt ,
2062
+ unstable_opts : & UnstableOptions ,
2063
+ ( print_name, print_kind) : ( & str , PrintKind ) ,
2064
+ ) {
2065
+ match print_kind {
2066
+ PrintKind :: AllTargetSpecs | PrintKind :: CheckCfg | PrintKind :: TargetSpec
2067
+ if !unstable_opts. unstable_options =>
2068
+ {
2069
+ early_dcx. early_fatal ( format ! (
2070
+ "the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2071
+ print option"
2072
+ ) ) ;
2073
+ }
2074
+ _ => { }
2075
+ }
2076
+ }
2077
+
2078
+ fn emit_unknown_print_request_help ( early_dcx : & EarlyDiagCtxt , req : & str ) -> ! {
2079
+ let prints = PRINT_KINDS . iter ( ) . map ( |( name, _) | format ! ( "`{name}`" ) ) . collect :: < Vec < _ > > ( ) ;
2080
+ let prints = prints. join ( ", " ) ;
2081
+
2082
+ let mut diag = early_dcx. early_struct_fatal ( format ! ( "unknown print request: `{req}`" ) ) ;
2083
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
2084
+ diag. help ( format ! ( "valid print requests are: {prints}" ) ) ;
2085
+ diag. emit ( )
2086
+ }
2087
+
2096
2088
pub fn parse_target_triple ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> TargetTuple {
2097
2089
match matches. opt_str ( "target" ) {
2098
2090
Some ( target) if target. ends_with ( ".json" ) => {
0 commit comments