@@ -224,15 +224,10 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
224
224
// available for future dynamic libraries opened. This is currently used by
225
225
// loading LLVM and then making its symbols available for other dynamic
226
226
// 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
+ } ) ;
236
231
unsafe {
237
232
match lib. symbol ( "__rustc_codegen_backend" ) {
238
233
Ok ( f) => {
@@ -337,28 +332,22 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
337
332
f. exists ( )
338
333
} )
339
334
. 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
+ } ) ;
352
344
info ! ( "probing {} for a codegen backend" , sysroot. display( ) ) ;
353
345
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
+ } ) ;
362
351
363
352
let mut file: Option < PathBuf > = None ;
364
353
@@ -1055,10 +1044,8 @@ impl RustcDefaultCalls {
1055
1044
Sysroot => println ! ( "{}" , sess. sysroot( ) . display( ) ) ,
1056
1045
TargetSpec => println ! ( "{}" , sess. target. target. to_json( ) . pretty( ) ) ,
1057
1046
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" ) ) ;
1062
1049
let attrs = attrs. as_ref ( ) . unwrap ( ) ;
1063
1050
let t_outputs = driver:: build_output_filenames ( input, odir, ofile, attrs, sess) ;
1064
1051
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> {
1406
1393
for option in config:: rustc_optgroups ( ) {
1407
1394
( option. apply ) ( & mut options) ;
1408
1395
}
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 ( ) ) ) ;
1413
1398
1414
1399
// For all options we just parsed, we check a few aspects:
1415
1400
//
@@ -1631,7 +1616,7 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
1631
1616
}
1632
1617
}
1633
1618
1634
- if result. len ( ) > 0 {
1619
+ if ! result. is_empty ( ) {
1635
1620
Some ( ( result, excluded_cargo_defaults) )
1636
1621
} else {
1637
1622
None
0 commit comments