@@ -1221,17 +1221,30 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12211221 // Parse with *all* options defined in the compiler, we don't worry about
12221222 // option stability here we just want to parse as much as possible.
12231223 let mut options = getopts:: Options :: new( ) ;
1224- for option in config:: rustc_optgroups( ) {
1224+ let optgroups = config:: rustc_optgroups( ) ;
1225+ for option in & optgroups {
12251226 ( option. apply) ( & mut options) ;
12261227 }
12271228 let matches = options. parse( args) . unwrap_or_else( |e| {
1228- let msg = match e {
1229+ let msg: Option < String > = match e {
12291230 getopts:: Fail :: UnrecognizedOption ( ref opt) => CG_OPTIONS
12301231 . iter( )
12311232 . map( |& ( name, ..) | ( 'C' , name) )
12321233 . chain( Z_OPTIONS . iter( ) . map( |& ( name, ..) | ( 'Z' , name) ) )
12331234 . find( |& ( _, name) | * opt == name. replace( '_' , "-" ) )
12341235 . map( |( flag, _) | format!( "{e}. Did you mean `-{flag} {opt}`?" ) ) ,
1236+ getopts:: Fail :: ArgumentMissing ( ref opt) => {
1237+ optgroups. iter( ) . find( |option| option. name == opt) . map( |option| {
1238+ // Print the help just for the option in question.
1239+ let mut options = getopts:: Options :: new( ) ;
1240+ ( option. apply) ( & mut options) ;
1241+ // getopt requires us to pass a function for joining an iterator of
1242+ // strings, even though in this case we expect exactly one string.
1243+ options. usage_with_format( |it| {
1244+ it. fold( format!( "{e}\n Usage:" ) , |a, b| a + "\n " + & b)
1245+ } )
1246+ } )
1247+ }
12351248 _ => None ,
12361249 } ;
12371250 early_dcx. early_fatal( msg. unwrap_or_else( || e. to_string( ) ) ) ;
0 commit comments