@@ -596,7 +596,7 @@ pub(crate) fn cli() -> Command {
596
596
. help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
597
597
. long ( "toolchain" )
598
598
. num_args ( 1 )
599
- . value_parser ( partial_toolchain_desc_parser) ,
599
+ . value_parser ( partial_toolchain_desc_parser) ,
600
600
)
601
601
. arg (
602
602
Arg :: new ( "target" )
@@ -614,7 +614,7 @@ pub(crate) fn cli() -> Command {
614
614
. help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
615
615
. long ( "toolchain" )
616
616
. num_args ( 1 )
617
- . value_parser ( partial_toolchain_desc_parser) ,
617
+ . value_parser ( partial_toolchain_desc_parser) ,
618
618
)
619
619
. arg (
620
620
Arg :: new ( "target" )
@@ -1263,10 +1263,7 @@ fn show_rustup_home(cfg: &Cfg) -> Result<utils::ExitCode> {
1263
1263
}
1264
1264
1265
1265
fn target_list ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1266
- let toolchain = m
1267
- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1268
- . map ( Into :: into) ;
1269
- let toolchain = explicit_or_dir_toolchain2 ( cfg, toolchain) ?;
1266
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1270
1267
// downcasting required because the toolchain files can name any toolchain
1271
1268
let distributable = ( & toolchain) . try_into ( ) ?;
1272
1269
@@ -1278,10 +1275,7 @@ fn target_list(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1278
1275
}
1279
1276
1280
1277
fn target_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1281
- let toolchain_name = m
1282
- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1283
- . map ( Into :: into) ;
1284
- let toolchain = explicit_or_dir_toolchain2 ( cfg, toolchain_name) ?;
1278
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1285
1279
// XXX: long term move this error to cli ? the normal .into doesn't work
1286
1280
// because Result here is the wrong sort and expression type ascription
1287
1281
// isn't a feature yet.
@@ -1336,10 +1330,7 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1336
1330
}
1337
1331
1338
1332
fn target_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1339
- let toolchain = m
1340
- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1341
- . map ( Into :: into) ;
1342
- let toolchain = explicit_or_dir_toolchain2 ( cfg, toolchain) ?;
1333
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1343
1334
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1344
1335
1345
1336
for target in m. get_many :: < String > ( "target" ) . unwrap ( ) {
@@ -1355,7 +1346,7 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1355
1346
}
1356
1347
1357
1348
fn component_list ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1358
- let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1349
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1359
1350
// downcasting required because the toolchain files can name any toolchain
1360
1351
let distributable = ( & toolchain) . try_into ( ) ?;
1361
1352
@@ -1368,10 +1359,7 @@ fn component_list(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1368
1359
}
1369
1360
1370
1361
fn component_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1371
- let toolchain = m
1372
- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1373
- . map ( Into :: into) ;
1374
- let toolchain = explicit_or_dir_toolchain2 ( cfg, toolchain) ?;
1362
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1375
1363
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1376
1364
let target = get_target ( m, & distributable) ;
1377
1365
@@ -1392,7 +1380,7 @@ fn get_target(m: &ArgMatches, distributable: &DistributableToolchain<'_>) -> Opt
1392
1380
}
1393
1381
1394
1382
fn component_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1395
- let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1383
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1396
1384
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1397
1385
let target = get_target ( m, & distributable) ;
1398
1386
@@ -1405,9 +1393,11 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1405
1393
Ok ( utils:: ExitCode ( 0 ) )
1406
1394
}
1407
1395
1408
- fn explicit_or_dir_toolchain < ' a > ( cfg : & ' a Cfg , m : & ArgMatches ) -> Result < Toolchain < ' a > > {
1409
- let toolchain = m. get_one :: < ResolvableToolchainName > ( "toolchain" ) ;
1410
- explicit_or_dir_toolchain2 ( cfg, toolchain. cloned ( ) )
1396
+ // Make *sure* only to use this for a subcommand whose "toolchain" argument
1397
+ // has .value_parser(partial_toolchain_desc_parser), or it will panic.
1398
+ fn explicit_desc_or_dir_toolchain < ' a > ( cfg : & ' a Cfg , m : & ArgMatches ) -> Result < Toolchain < ' a > > {
1399
+ let toolchain = m. get_one :: < PartialToolchainDesc > ( "toolchain" ) . map ( Into :: into) ;
1400
+ explicit_or_dir_toolchain2 ( cfg, toolchain)
1411
1401
}
1412
1402
1413
1403
fn explicit_or_dir_toolchain2 (
@@ -1556,10 +1546,7 @@ const DOCS_DATA: &[(&str, &str, &str)] = &[
1556
1546
] ;
1557
1547
1558
1548
fn doc ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1559
- let toolchain = m
1560
- . get_one :: < PartialToolchainDesc > ( "toolchain" )
1561
- . map ( Into :: into) ;
1562
- let toolchain = explicit_or_dir_toolchain2 ( cfg, toolchain) ?;
1549
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1563
1550
1564
1551
if let Ok ( distributable) = DistributableToolchain :: try_from ( & toolchain) {
1565
1552
let manifestation = distributable. get_manifestation ( ) ?;
@@ -1613,7 +1600,7 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1613
1600
fn man ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1614
1601
let command = m. get_one :: < String > ( "command" ) . unwrap ( ) ;
1615
1602
1616
- let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
1603
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1617
1604
let mut path = toolchain. path ( ) . to_path_buf ( ) ;
1618
1605
path. push ( "share" ) ;
1619
1606
path. push ( "man" ) ;
0 commit comments