@@ -1296,8 +1296,10 @@ fn parse_output_types(
1296
1296
if !debugging_opts. parse_only {
1297
1297
for list in matches. opt_strs ( "emit" ) {
1298
1298
for output_type in list. split ( ',' ) {
1299
- let mut parts = output_type. splitn ( 2 , '=' ) ;
1300
- let shorthand = parts. next ( ) . unwrap ( ) ;
1299
+ let ( shorthand, path) = match output_type. split_once ( '=' ) {
1300
+ None => ( output_type, None ) ,
1301
+ Some ( ( shorthand, path) ) => ( shorthand, Some ( PathBuf :: from ( path) ) ) ,
1302
+ } ;
1301
1303
let output_type = OutputType :: from_shorthand ( shorthand) . unwrap_or_else ( || {
1302
1304
early_error (
1303
1305
error_format,
@@ -1308,7 +1310,6 @@ fn parse_output_types(
1308
1310
) ,
1309
1311
)
1310
1312
} ) ;
1311
- let path = parts. next ( ) . map ( PathBuf :: from) ;
1312
1313
output_types. insert ( output_type, path) ;
1313
1314
}
1314
1315
}
@@ -1452,11 +1453,10 @@ fn parse_opt_level(
1452
1453
let max_c = matches
1453
1454
. opt_strs_pos ( "C" )
1454
1455
. into_iter ( )
1455
- . flat_map (
1456
- |( i, s) | {
1457
- if let Some ( "opt-level" ) = s. splitn ( 2 , '=' ) . next ( ) { Some ( i) } else { None }
1458
- } ,
1459
- )
1456
+ . flat_map ( |( i, s) | {
1457
+ // NB: This can match a string without `=`.
1458
+ if let Some ( "opt-level" ) = s. splitn ( 2 , '=' ) . next ( ) { Some ( i) } else { None }
1459
+ } )
1460
1460
. max ( ) ;
1461
1461
if max_o > max_c {
1462
1462
OptLevel :: Default
@@ -1491,11 +1491,10 @@ fn select_debuginfo(
1491
1491
let max_c = matches
1492
1492
. opt_strs_pos ( "C" )
1493
1493
. into_iter ( )
1494
- . flat_map (
1495
- |( i, s) | {
1496
- if let Some ( "debuginfo" ) = s. splitn ( 2 , '=' ) . next ( ) { Some ( i) } else { None }
1497
- } ,
1498
- )
1494
+ . flat_map ( |( i, s) | {
1495
+ // NB: This can match a string without `=`.
1496
+ if let Some ( "debuginfo" ) = s. splitn ( 2 , '=' ) . next ( ) { Some ( i) } else { None }
1497
+ } )
1499
1498
. max ( ) ;
1500
1499
if max_g > max_c {
1501
1500
DebugInfo :: Full
@@ -1528,23 +1527,26 @@ fn parse_libs(
1528
1527
. map ( |s| {
1529
1528
// Parse string of the form "[KIND=]lib[:new_name]",
1530
1529
// where KIND is one of "dylib", "framework", "static".
1531
- let mut parts = s. splitn ( 2 , '=' ) ;
1532
- let kind = parts. next ( ) . unwrap ( ) ;
1533
- let ( name, kind) = match ( parts. next ( ) , kind) {
1534
- ( None , name) => ( name, NativeLibKind :: Unspecified ) ,
1535
- ( Some ( name) , "dylib" ) => ( name, NativeLibKind :: Dylib ) ,
1536
- ( Some ( name) , "framework" ) => ( name, NativeLibKind :: Framework ) ,
1537
- ( Some ( name) , "static" ) => ( name, NativeLibKind :: StaticBundle ) ,
1538
- ( Some ( name) , "static-nobundle" ) => ( name, NativeLibKind :: StaticNoBundle ) ,
1539
- ( _, s) => {
1540
- early_error (
1541
- error_format,
1542
- & format ! (
1543
- "unknown library kind `{}`, expected \
1544
- one of dylib, framework, or static",
1545
- s
1546
- ) ,
1547
- ) ;
1530
+ let ( name, kind) = match s. split_once ( '=' ) {
1531
+ None => ( s, NativeLibKind :: Unspecified ) ,
1532
+ Some ( ( kind, name) ) => {
1533
+ let kind = match kind {
1534
+ "dylib" => NativeLibKind :: Dylib ,
1535
+ "framework" => NativeLibKind :: Framework ,
1536
+ "static" => NativeLibKind :: StaticBundle ,
1537
+ "static-nobundle" => NativeLibKind :: StaticNoBundle ,
1538
+ s => {
1539
+ early_error (
1540
+ error_format,
1541
+ & format ! (
1542
+ "unknown library kind `{}`, expected \
1543
+ one of dylib, framework, or static",
1544
+ s
1545
+ ) ,
1546
+ ) ;
1547
+ }
1548
+ } ;
1549
+ ( name. to_string ( ) , kind)
1548
1550
}
1549
1551
} ;
1550
1552
if kind == NativeLibKind :: StaticNoBundle
@@ -1556,10 +1558,11 @@ fn parse_libs(
1556
1558
accepted on the nightly compiler",
1557
1559
) ;
1558
1560
}
1559
- let mut name_parts = name. splitn ( 2 , ':' ) ;
1560
- let name = name_parts. next ( ) . unwrap ( ) ;
1561
- let new_name = name_parts. next ( ) ;
1562
- ( name. to_owned ( ) , new_name. map ( |n| n. to_owned ( ) ) , kind)
1561
+ let ( name, new_name) = match name. split_once ( ':' ) {
1562
+ None => ( name, None ) ,
1563
+ Some ( ( name, new_name) ) => ( name. to_string ( ) , Some ( new_name. to_owned ( ) ) ) ,
1564
+ } ;
1565
+ ( name, new_name, kind)
1563
1566
} )
1564
1567
. collect ( )
1565
1568
}
@@ -1580,20 +1583,13 @@ pub fn parse_externs(
1580
1583
let is_unstable_enabled = debugging_opts. unstable_options ;
1581
1584
let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
1582
1585
for arg in matches. opt_strs ( "extern" ) {
1583
- let mut parts = arg. splitn ( 2 , '=' ) ;
1584
- let name = parts
1585
- . next ( )
1586
- . unwrap_or_else ( || early_error ( error_format, "--extern value must not be empty" ) ) ;
1587
- let path = parts. next ( ) . map ( |s| s. to_string ( ) ) ;
1588
-
1589
- let mut name_parts = name. splitn ( 2 , ':' ) ;
1590
- let first_part = name_parts. next ( ) ;
1591
- let second_part = name_parts. next ( ) ;
1592
- let ( options, name) = match ( first_part, second_part) {
1593
- ( Some ( opts) , Some ( name) ) => ( Some ( opts) , name) ,
1594
- ( Some ( name) , None ) => ( None , name) ,
1595
- ( None , None ) => early_error ( error_format, "--extern name must not be empty" ) ,
1596
- _ => unreachable ! ( ) ,
1586
+ let ( name, path) = match arg. split_once ( '=' ) {
1587
+ None => ( arg, None ) ,
1588
+ Some ( ( name, path) ) => ( name. to_string ( ) , Some ( path. to_string ( ) ) ) ,
1589
+ } ;
1590
+ let ( options, name) = match name. split_once ( ':' ) {
1591
+ None => ( None , name) ,
1592
+ Some ( ( opts, name) ) => ( Some ( opts) , name. to_string ( ) ) ,
1597
1593
} ;
1598
1594
1599
1595
let entry = externs. entry ( name. to_owned ( ) ) ;
@@ -1682,17 +1678,12 @@ fn parse_remap_path_prefix(
1682
1678
matches
1683
1679
. opt_strs ( "remap-path-prefix" )
1684
1680
. into_iter ( )
1685
- . map ( |remap| {
1686
- let mut parts = remap. rsplitn ( 2 , '=' ) ; // reverse iterator
1687
- let to = parts. next ( ) ;
1688
- let from = parts. next ( ) ;
1689
- match ( from, to) {
1690
- ( Some ( from) , Some ( to) ) => ( PathBuf :: from ( from) , PathBuf :: from ( to) ) ,
1691
- _ => early_error (
1692
- error_format,
1693
- "--remap-path-prefix must contain '=' between FROM and TO" ,
1694
- ) ,
1695
- }
1681
+ . map ( |remap| match remap. rsplit_once ( '=' ) {
1682
+ None => early_error (
1683
+ error_format,
1684
+ "--remap-path-prefix must contain '=' between FROM and TO" ,
1685
+ ) ,
1686
+ Some ( ( from, to) ) => ( PathBuf :: from ( from) , PathBuf :: from ( to) ) ,
1696
1687
} )
1697
1688
. collect ( )
1698
1689
}
0 commit comments