@@ -431,7 +431,7 @@ impl Config {
431
431
None => {
432
432
let mut t = getenv_unwrap ( "TARGET" ) ;
433
433
if t. ends_with ( "-darwin" ) && self . uses_cxx11 {
434
- t = t + "11"
434
+ t += "11"
435
435
}
436
436
t
437
437
}
@@ -507,14 +507,14 @@ impl Config {
507
507
}
508
508
let system_prefix = self
509
509
. getenv_target_os ( "CMAKE_PREFIX_PATH" )
510
- . unwrap_or ( OsString :: new ( ) ) ;
511
- cmake_prefix_path. extend ( env:: split_paths ( & system_prefix) . map ( |s| s . to_owned ( ) ) ) ;
510
+ . unwrap_or_default ( ) ;
511
+ cmake_prefix_path. extend ( env:: split_paths ( & system_prefix) ) ;
512
512
let cmake_prefix_path = env:: join_paths ( & cmake_prefix_path) . unwrap ( ) ;
513
513
514
514
// Build up the first cmake command to build the build system.
515
515
let executable = self
516
516
. getenv_target_os ( "CMAKE" )
517
- . unwrap_or ( OsString :: from ( "cmake" ) ) ;
517
+ . unwrap_or_else ( || OsString :: from ( "cmake" ) ) ;
518
518
let mut cmd = Command :: new ( & executable) ;
519
519
520
520
if self . verbose_cmake {
@@ -582,13 +582,14 @@ impl Config {
582
582
// If we're on MSVC we need to be sure to use the right generator or
583
583
// otherwise we won't get 32/64 bit correct automatically.
584
584
// This also guarantees that NMake generator isn't chosen implicitly.
585
- let using_nmake_generator;
586
- if generator. is_none ( ) {
587
- cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
588
- using_nmake_generator = false ;
589
- } else {
590
- using_nmake_generator = generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles" ;
591
- }
585
+ let using_nmake_generator = {
586
+ if generator. is_none ( ) {
587
+ cmd. arg ( "-G" ) . arg ( self . visual_studio_generator ( & target) ) ;
588
+ false
589
+ } else {
590
+ generator. as_ref ( ) . unwrap ( ) == "NMake Makefiles"
591
+ }
592
+ } ;
592
593
if !is_ninja && !using_nmake_generator {
593
594
if target. contains ( "x86_64" ) {
594
595
if self . generator_toolset . is_none ( ) {
@@ -774,7 +775,10 @@ impl Config {
774
775
}
775
776
776
777
// And build!
777
- let target = self . cmake_target . clone ( ) . unwrap_or ( "install" . to_string ( ) ) ;
778
+ let target = self
779
+ . cmake_target
780
+ . clone ( )
781
+ . unwrap_or_else ( || "install" . to_string ( ) ) ;
778
782
let mut cmd = Command :: new ( & executable) ;
779
783
cmd. current_dir ( & build) ;
780
784
@@ -823,7 +827,7 @@ impl Config {
823
827
run ( & mut cmd, "cmake" ) ;
824
828
825
829
println ! ( "cargo:root={}" , dst. display( ) ) ;
826
- return dst;
830
+ dst
827
831
}
828
832
829
833
fn getenv_os ( & mut self , v : & str ) -> Option < OsString > {
@@ -845,7 +849,7 @@ impl Config {
845
849
. unwrap_or_else ( || getenv_unwrap ( "TARGET" ) ) ;
846
850
847
851
let kind = if host == target { "HOST" } else { "TARGET" } ;
848
- let target_u = target. replace ( "-" , "_" ) ;
852
+ let target_u = target. replace ( '-' , "_" ) ;
849
853
self . getenv_os ( & format ! ( "{}_{}" , var_base, target) )
850
854
. or_else ( || self . getenv_os ( & format ! ( "{}_{}" , var_base, target_u) ) )
851
855
. or_else ( || self . getenv_os ( & format ! ( "{}_{}" , kind, var_base) ) )
@@ -894,7 +898,7 @@ impl Config {
894
898
// CMake will apparently store canonicalized paths which normally
895
899
// isn't relevant to us but we canonicalize it here to ensure
896
900
// we're both checking the same thing.
897
- let path = fs:: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ;
901
+ let path = fs:: canonicalize ( & self . path ) . unwrap_or_else ( |_| self . path . clone ( ) ) ;
898
902
let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
899
903
Ok ( f) => f,
900
904
Err ( ..) => return ,
@@ -949,10 +953,10 @@ fn run(cmd: &mut Command, program: &str) {
949
953
}
950
954
951
955
fn find_exe ( path : & Path ) -> PathBuf {
952
- env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or ( OsString :: new ( ) ) )
956
+ env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) )
953
957
. map ( |p| p. join ( path) )
954
958
. find ( |p| fs:: metadata ( p) . is_ok ( ) )
955
- . unwrap_or ( path. to_owned ( ) )
959
+ . unwrap_or_else ( || path. to_owned ( ) )
956
960
}
957
961
958
962
fn getenv_unwrap ( v : & str ) -> String {
0 commit comments