@@ -37,7 +37,7 @@ use rustc_metadata::locator;
3737use rustc_session:: config:: { nightly_options, CG_OPTIONS , Z_OPTIONS } ;
3838use rustc_session:: config:: { ErrorOutputType , Input , OutputType , PrintRequest , TrimmedDefPaths } ;
3939use rustc_session:: cstore:: MetadataLoader ;
40- use rustc_session:: getopts;
40+ use rustc_session:: getopts:: { self , Matches } ;
4141use rustc_session:: lint:: { Lint , LintId } ;
4242use rustc_session:: { config, Session } ;
4343use rustc_session:: { early_error, early_error_no_abort, early_warn} ;
@@ -956,6 +956,46 @@ Available lint options:
956956 }
957957}
958958
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+
959999fn describe_debug_flags ( ) {
9601000 println ! ( "\n Available options:\n " ) ;
9611001 print_flag_list ( "-Z" , config:: Z_OPTIONS ) ;
@@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
9661006 print_flag_list ( "-C" , config:: CG_OPTIONS ) ;
9671007}
9681008
969- pub fn print_flag_list < T > (
1009+ fn print_flag_list < T > (
9701010 cmdline_opt : & str ,
9711011 flag_list : & [ ( & ' static str , T , & ' static str , & ' static str ) ] ,
9721012) {
@@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10591099 return None ;
10601100 }
10611101
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) {
10931103 return None ;
10941104 }
10951105
0 commit comments