@@ -1296,8 +1296,10 @@ fn parse_output_types(
12961296 if !debugging_opts. parse_only {
12971297 for list in matches. opt_strs ( "emit" ) {
12981298 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+ } ;
13011303 let output_type = OutputType :: from_shorthand ( shorthand) . unwrap_or_else ( || {
13021304 early_error (
13031305 error_format,
@@ -1308,7 +1310,6 @@ fn parse_output_types(
13081310 ) ,
13091311 )
13101312 } ) ;
1311- let path = parts. next ( ) . map ( PathBuf :: from) ;
13121313 output_types. insert ( output_type, path) ;
13131314 }
13141315 }
@@ -1452,11 +1453,10 @@ fn parse_opt_level(
14521453 let max_c = matches
14531454 . opt_strs_pos ( "C" )
14541455 . 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+ } )
14601460 . max ( ) ;
14611461 if max_o > max_c {
14621462 OptLevel :: Default
@@ -1491,11 +1491,10 @@ fn select_debuginfo(
14911491 let max_c = matches
14921492 . opt_strs_pos ( "C" )
14931493 . 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+ } )
14991498 . max ( ) ;
15001499 if max_g > max_c {
15011500 DebugInfo :: Full
@@ -1528,23 +1527,26 @@ fn parse_libs(
15281527 . map ( |s| {
15291528 // Parse string of the form "[KIND=]lib[:new_name]",
15301529 // 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)
15481550 }
15491551 } ;
15501552 if kind == NativeLibKind :: StaticNoBundle
@@ -1556,10 +1558,11 @@ fn parse_libs(
15561558 accepted on the nightly compiler",
15571559 ) ;
15581560 }
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)
15631566 } )
15641567 . collect ( )
15651568}
@@ -1580,20 +1583,13 @@ pub fn parse_externs(
15801583 let is_unstable_enabled = debugging_opts. unstable_options ;
15811584 let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
15821585 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 ( ) ) ,
15971593 } ;
15981594
15991595 let entry = externs. entry ( name. to_owned ( ) ) ;
@@ -1682,17 +1678,12 @@ fn parse_remap_path_prefix(
16821678 matches
16831679 . opt_strs ( "remap-path-prefix" )
16841680 . 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) ) ,
16961687 } )
16971688 . collect ( )
16981689}
0 commit comments