@@ -224,15 +224,10 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
224224 // available for future dynamic libraries opened. This is currently used by
225225 // loading LLVM and then making its symbols available for other dynamic
226226 // libraries.
227- let lib = match DynamicLibrary :: open_global_now ( path) {
228- Ok ( lib) => lib,
229- Err ( err) => {
230- let err = format ! ( "couldn't load codegen backend {:?}: {:?}" ,
231- path,
232- err) ;
233- early_error ( ErrorOutputType :: default ( ) , & err) ;
234- }
235- } ;
227+ let lib = DynamicLibrary :: open_global_now ( path) . unwrap_or_else ( |err| {
228+ let err = format ! ( "couldn't load codegen backend {:?}: {:?}" , path, err) ;
229+ early_error ( ErrorOutputType :: default ( ) , & err) ;
230+ } ) ;
236231 unsafe {
237232 match lib. symbol ( "__rustc_codegen_backend" ) {
238233 Ok ( f) => {
@@ -337,28 +332,22 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
337332 f. exists ( )
338333 } )
339334 . next ( ) ;
340- let sysroot = match sysroot {
341- Some ( path) => path,
342- None => {
343- let candidates = sysroot_candidates. iter ( )
344- . map ( |p| p. display ( ) . to_string ( ) )
345- . collect :: < Vec < _ > > ( )
346- . join ( "\n * " ) ;
347- let err = format ! ( "failed to find a `codegen-backends` folder \
348- in the sysroot candidates:\n * {}", candidates) ;
349- early_error ( ErrorOutputType :: default ( ) , & err) ;
350- }
351- } ;
335+ let sysroot = sysroot. unwrap_or_else ( || {
336+ let candidates = sysroot_candidates. iter ( )
337+ . map ( |p| p. display ( ) . to_string ( ) )
338+ . collect :: < Vec < _ > > ( )
339+ . join ( "\n * " ) ;
340+ let err = format ! ( "failed to find a `codegen-backends` folder \
341+ in the sysroot candidates:\n * {}", candidates) ;
342+ early_error ( ErrorOutputType :: default ( ) , & err) ;
343+ } ) ;
352344 info ! ( "probing {} for a codegen backend" , sysroot. display( ) ) ;
353345
354- let d = match sysroot. read_dir ( ) {
355- Ok ( d) => d,
356- Err ( e) => {
357- let err = format ! ( "failed to load default codegen backend, couldn't \
358- read `{}`: {}", sysroot. display( ) , e) ;
359- early_error ( ErrorOutputType :: default ( ) , & err) ;
360- }
361- } ;
346+ let d = sysroot. read_dir ( ) . unwrap_or_else ( |e| {
347+ let err = format ! ( "failed to load default codegen backend, couldn't \
348+ read `{}`: {}", sysroot. display( ) , e) ;
349+ early_error ( ErrorOutputType :: default ( ) , & err) ;
350+ } ) ;
362351
363352 let mut file: Option < PathBuf > = None ;
364353
@@ -1055,10 +1044,8 @@ impl RustcDefaultCalls {
10551044 Sysroot => println ! ( "{}" , sess. sysroot( ) . display( ) ) ,
10561045 TargetSpec => println ! ( "{}" , sess. target. target. to_json( ) . pretty( ) ) ,
10571046 FileNames | CrateName => {
1058- let input = match input {
1059- Some ( input) => input,
1060- None => early_error ( ErrorOutputType :: default ( ) , "no input file provided" ) ,
1061- } ;
1047+ let input = input. unwrap_or_else ( ||
1048+ early_error ( ErrorOutputType :: default ( ) , "no input file provided" ) ) ;
10621049 let attrs = attrs. as_ref ( ) . unwrap ( ) ;
10631050 let t_outputs = driver:: build_output_filenames ( input, odir, ofile, attrs, sess) ;
10641051 let id = rustc_codegen_utils:: link:: find_crate_name ( Some ( sess) , attrs, input) ;
@@ -1406,10 +1393,8 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
14061393 for option in config:: rustc_optgroups ( ) {
14071394 ( option. apply ) ( & mut options) ;
14081395 }
1409- let matches = match options. parse ( args) {
1410- Ok ( m) => m,
1411- Err ( f) => early_error ( ErrorOutputType :: default ( ) , & f. to_string ( ) ) ,
1412- } ;
1396+ let matches = options. parse ( args) . unwrap_or_else ( |f|
1397+ early_error ( ErrorOutputType :: default ( ) , & f. to_string ( ) ) ) ;
14131398
14141399 // For all options we just parsed, we check a few aspects:
14151400 //
@@ -1631,7 +1616,7 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
16311616 }
16321617 }
16331618
1634- if result. len ( ) > 0 {
1619+ if ! result. is_empty ( ) {
16351620 Some ( ( result, excluded_cargo_defaults) )
16361621 } else {
16371622 None
0 commit comments