@@ -1453,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
1453
1453
if sess. opts . crate_types . contains ( & CrateType :: ProcMacro ) {
1454
1454
ret. insert ( ( Symbol :: intern ( "proc_macro" ) , None ) ) ;
1455
1455
}
1456
- return ret;
1456
+ ret
1457
1457
}
1458
1458
1459
1459
pub fn build_configuration ( sess : & Session , mut user_cfg : ast:: CrateConfig ) -> ast:: CrateConfig {
@@ -1469,15 +1469,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
1469
1469
}
1470
1470
1471
1471
pub fn build_target_config ( opts : & Options , sp : & Handler ) -> Config {
1472
- let target = match Target :: search ( & opts. target_triple ) {
1473
- Ok ( t) => t,
1474
- Err ( e) => {
1475
- sp. struct_fatal ( & format ! ( "Error loading target specification: {}" , e) )
1476
- . help ( "Use `--print target-list` for a list of built-in targets" )
1477
- . emit ( ) ;
1478
- FatalError . raise ( ) ;
1479
- }
1480
- } ;
1472
+ let target = Target :: search ( & opts. target_triple ) . unwrap_or_else ( |e| {
1473
+ sp. struct_fatal ( & format ! ( "Error loading target specification: {}" , e) )
1474
+ . help ( "Use `--print target-list` for a list of built-in targets" )
1475
+ . emit ( ) ;
1476
+ FatalError . raise ( ) ;
1477
+ } ) ;
1481
1478
1482
1479
let ( isize_ty, usize_ty) = match & target. target_pointer_width [ ..] {
1483
1480
"16" => ( ast:: IntTy :: I16 , ast:: UintTy :: U16 ) ,
@@ -1842,9 +1839,8 @@ pub fn build_session_options_and_crate_config(
1842
1839
} ;
1843
1840
1844
1841
let edition = match matches. opt_str ( "edition" ) {
1845
- Some ( arg) => match Edition :: from_str ( & arg) {
1846
- Ok ( edition) => edition,
1847
- Err ( _) => early_error (
1842
+ Some ( arg) => Edition :: from_str ( & arg) . unwrap_or_else ( |_|
1843
+ early_error (
1848
1844
ErrorOutputType :: default ( ) ,
1849
1845
& format ! (
1850
1846
"argument for --edition must be one of: \
@@ -1853,7 +1849,7 @@ pub fn build_session_options_and_crate_config(
1853
1849
arg
1854
1850
) ,
1855
1851
) ,
1856
- }
1852
+ ) ,
1857
1853
None => DEFAULT_EDITION ,
1858
1854
} ;
1859
1855
@@ -1922,17 +1918,16 @@ pub fn build_session_options_and_crate_config(
1922
1918
for output_type in list. split ( ',' ) {
1923
1919
let mut parts = output_type. splitn ( 2 , '=' ) ;
1924
1920
let shorthand = parts. next ( ) . unwrap ( ) ;
1925
- let output_type = match OutputType :: from_shorthand ( shorthand) {
1926
- Some ( output_type) => output_type,
1927
- None => early_error (
1921
+ let output_type = OutputType :: from_shorthand ( shorthand) . unwrap_or_else ( ||
1922
+ early_error (
1928
1923
error_format,
1929
1924
& format ! (
1930
1925
"unknown emission type: `{}` - expected one of: {}" ,
1931
1926
shorthand,
1932
1927
OutputType :: shorthands_display( ) ,
1933
1928
) ,
1934
1929
) ,
1935
- } ;
1930
+ ) ;
1936
1931
let path = parts. next ( ) . map ( PathBuf :: from) ;
1937
1932
output_types. insert ( output_type, path) ;
1938
1933
}
@@ -2060,12 +2055,8 @@ pub fn build_session_options_and_crate_config(
2060
2055
let target_triple = if let Some ( target) = matches. opt_str ( "target" ) {
2061
2056
if target. ends_with ( ".json" ) {
2062
2057
let path = Path :: new ( & target) ;
2063
- match TargetTriple :: from_path ( & path) {
2064
- Ok ( triple) => triple,
2065
- Err ( _) => {
2066
- early_error ( error_format, & format ! ( "target file {:?} does not exist" , path) )
2067
- }
2068
- }
2058
+ TargetTriple :: from_path ( & path) . unwrap_or_else ( |_|
2059
+ early_error ( error_format, & format ! ( "target file {:?} does not exist" , path) ) )
2069
2060
} else {
2070
2061
TargetTriple :: TargetTriple ( target)
2071
2062
}
@@ -2220,10 +2211,8 @@ pub fn build_session_options_and_crate_config(
2220
2211
let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2221
2212
for arg in & matches. opt_strs ( "extern" ) {
2222
2213
let mut parts = arg. splitn ( 2 , '=' ) ;
2223
- let name = match parts. next ( ) {
2224
- Some ( s) => s,
2225
- None => early_error ( error_format, "--extern value must not be empty" ) ,
2226
- } ;
2214
+ let name = parts. next ( ) . unwrap_or_else ( ||
2215
+ early_error ( error_format, "--extern value must not be empty" ) ) ;
2227
2216
let location = parts. next ( ) . map ( |s| s. to_string ( ) ) ;
2228
2217
if location. is_none ( ) && !is_unstable_enabled {
2229
2218
early_error (
0 commit comments