@@ -37,7 +37,7 @@ use rustc_metadata::locator;
37
37
use rustc_session:: config:: { nightly_options, CG_OPTIONS , Z_OPTIONS } ;
38
38
use rustc_session:: config:: { ErrorOutputType , Input , OutputType , PrintRequest , TrimmedDefPaths } ;
39
39
use rustc_session:: cstore:: MetadataLoader ;
40
- use rustc_session:: getopts;
40
+ use rustc_session:: getopts:: { self , Matches } ;
41
41
use rustc_session:: lint:: { Lint , LintId } ;
42
42
use rustc_session:: { config, Session } ;
43
43
use rustc_session:: { early_error, early_error_no_abort, early_warn} ;
@@ -956,6 +956,46 @@ Available lint options:
956
956
}
957
957
}
958
958
959
+ /// Show help for flag categories shared between rustdoc and rustc.
960
+ ///
961
+ /// Returns whether a help option was printed.
962
+ pub fn describe_flag_categories ( matches : & Matches ) -> bool {
963
+ // Handle the special case of -Wall.
964
+ let wall = matches. opt_strs ( "W" ) ;
965
+ if wall. iter ( ) . any ( |x| * x == "all" ) {
966
+ print_wall_help ( ) ;
967
+ rustc_errors:: FatalError . raise ( ) ;
968
+ }
969
+
970
+ // Don't handle -W help here, because we might first load plugins.
971
+ let debug_flags = matches. opt_strs ( "Z" ) ;
972
+ if debug_flags. iter ( ) . any ( |x| * x == "help" ) {
973
+ describe_debug_flags ( ) ;
974
+ return true ;
975
+ }
976
+
977
+ let cg_flags = matches. opt_strs ( "C" ) ;
978
+ if cg_flags. iter ( ) . any ( |x| * x == "help" ) {
979
+ describe_codegen_flags ( ) ;
980
+ return true ;
981
+ }
982
+
983
+ if cg_flags. iter ( ) . any ( |x| * x == "no-stack-check" ) {
984
+ early_warn (
985
+ ErrorOutputType :: default ( ) ,
986
+ "the --no-stack-check flag is deprecated and does nothing" ,
987
+ ) ;
988
+ }
989
+
990
+ if cg_flags. iter ( ) . any ( |x| * x == "passes=list" ) {
991
+ let backend_name = debug_flags. iter ( ) . find_map ( |x| x. strip_prefix ( "codegen-backend=" ) ) ;
992
+ get_codegen_backend ( & None , backend_name) . print_passes ( ) ;
993
+ return true ;
994
+ }
995
+
996
+ false
997
+ }
998
+
959
999
fn describe_debug_flags ( ) {
960
1000
println ! ( "\n Available options:\n " ) ;
961
1001
print_flag_list ( "-Z" , config:: Z_OPTIONS ) ;
@@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
966
1006
print_flag_list ( "-C" , config:: CG_OPTIONS ) ;
967
1007
}
968
1008
969
- pub fn print_flag_list < T > (
1009
+ fn print_flag_list < T > (
970
1010
cmdline_opt : & str ,
971
1011
flag_list : & [ ( & ' static str , T , & ' static str , & ' static str ) ] ,
972
1012
) {
@@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
1059
1099
return None ;
1060
1100
}
1061
1101
1062
- // Handle the special case of -Wall.
1063
- let wall = matches. opt_strs ( "W" ) ;
1064
- if wall. iter ( ) . any ( |x| * x == "all" ) {
1065
- print_wall_help ( ) ;
1066
- rustc_errors:: FatalError . raise ( ) ;
1067
- }
1068
-
1069
- // Don't handle -W help here, because we might first load plugins.
1070
- let debug_flags = matches. opt_strs ( "Z" ) ;
1071
- if debug_flags. iter ( ) . any ( |x| * x == "help" ) {
1072
- describe_debug_flags ( ) ;
1073
- return None ;
1074
- }
1075
-
1076
- let cg_flags = matches. opt_strs ( "C" ) ;
1077
-
1078
- if cg_flags. iter ( ) . any ( |x| * x == "help" ) {
1079
- describe_codegen_flags ( ) ;
1080
- return None ;
1081
- }
1082
-
1083
- if cg_flags. iter ( ) . any ( |x| * x == "no-stack-check" ) {
1084
- early_warn (
1085
- ErrorOutputType :: default ( ) ,
1086
- "the --no-stack-check flag is deprecated and does nothing" ,
1087
- ) ;
1088
- }
1089
-
1090
- if cg_flags. iter ( ) . any ( |x| * x == "passes=list" ) {
1091
- let backend_name = debug_flags. iter ( ) . find_map ( |x| x. strip_prefix ( "codegen-backend=" ) ) ;
1092
- get_codegen_backend ( & None , backend_name) . print_passes ( ) ;
1102
+ if describe_flag_categories ( & matches) {
1093
1103
return None ;
1094
1104
}
1095
1105
0 commit comments