@@ -1221,17 +1221,30 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
1221
1221
// Parse with *all* options defined in the compiler, we don't worry about
1222
1222
// option stability here we just want to parse as much as possible.
1223
1223
let mut options = getopts:: Options :: new( ) ;
1224
- for option in config:: rustc_optgroups( ) {
1224
+ let optgroups = config:: rustc_optgroups( ) ;
1225
+ for option in & optgroups {
1225
1226
( option. apply) ( & mut options) ;
1226
1227
}
1227
1228
let matches = options. parse( args) . unwrap_or_else( |e| {
1228
- let msg = match e {
1229
+ let msg: Option < String > = match e {
1229
1230
getopts:: Fail :: UnrecognizedOption ( ref opt) => CG_OPTIONS
1230
1231
. iter( )
1231
1232
. map( |& ( name, ..) | ( 'C' , name) )
1232
1233
. chain( Z_OPTIONS . iter( ) . map( |& ( name, ..) | ( 'Z' , name) ) )
1233
1234
. find( |& ( _, name) | * opt == name. replace( '_' , "-" ) )
1234
1235
. 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
+ }
1235
1248
_ => None ,
1236
1249
} ;
1237
1250
early_dcx. early_fatal( msg. unwrap_or_else( || e. to_string( ) ) ) ;
0 commit comments