@@ -1453,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
14531453 if sess. opts . crate_types . contains ( & CrateType :: ProcMacro ) {
14541454 ret. insert ( ( Symbol :: intern ( "proc_macro" ) , None ) ) ;
14551455 }
1456- return ret;
1456+ ret
14571457}
14581458
14591459pub 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
14691469}
14701470
14711471pub 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+ } ) ;
14811478
14821479 let ( isize_ty, usize_ty) = match & target. target_pointer_width [ ..] {
14831480 "16" => ( ast:: IntTy :: I16 , ast:: UintTy :: U16 ) ,
@@ -1842,9 +1839,8 @@ pub fn build_session_options_and_crate_config(
18421839 } ;
18431840
18441841 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 (
18481844 ErrorOutputType :: default ( ) ,
18491845 & format ! (
18501846 "argument for --edition must be one of: \
@@ -1853,7 +1849,7 @@ pub fn build_session_options_and_crate_config(
18531849 arg
18541850 ) ,
18551851 ) ,
1856- }
1852+ ) ,
18571853 None => DEFAULT_EDITION ,
18581854 } ;
18591855
@@ -1922,17 +1918,16 @@ pub fn build_session_options_and_crate_config(
19221918 for output_type in list. split ( ',' ) {
19231919 let mut parts = output_type. splitn ( 2 , '=' ) ;
19241920 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 (
19281923 error_format,
19291924 & format ! (
19301925 "unknown emission type: `{}` - expected one of: {}" ,
19311926 shorthand,
19321927 OutputType :: shorthands_display( ) ,
19331928 ) ,
19341929 ) ,
1935- } ;
1930+ ) ;
19361931 let path = parts. next ( ) . map ( PathBuf :: from) ;
19371932 output_types. insert ( output_type, path) ;
19381933 }
@@ -2060,12 +2055,8 @@ pub fn build_session_options_and_crate_config(
20602055 let target_triple = if let Some ( target) = matches. opt_str ( "target" ) {
20612056 if target. ends_with ( ".json" ) {
20622057 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) ) )
20692060 } else {
20702061 TargetTriple :: TargetTriple ( target)
20712062 }
@@ -2220,10 +2211,8 @@ pub fn build_session_options_and_crate_config(
22202211 let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
22212212 for arg in & matches. opt_strs ( "extern" ) {
22222213 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" ) ) ;
22272216 let location = parts. next ( ) . map ( |s| s. to_string ( ) ) ;
22282217 if location. is_none ( ) && !is_unstable_enabled {
22292218 early_error (
0 commit comments