diff options
| author | bors <bors@rust-lang.org> | 2018-10-20 11:22:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-10-20 11:22:48 +0000 |
| commit | ca2639e82ec4a18d7359efbfb555ea69dd644c97 (patch) | |
| tree | 3dfa59589214b0157714150a785dd9cc4ccdc240 /src/libstd | |
| parent | 94273f4d8e463cac45486328294bb1c2bbc10170 (diff) | |
| parent | d28aed6dc45ffccc790469cb04f3f775ddb2283a (diff) | |
| download | rust-ca2639e82ec4a18d7359efbfb555ea69dd644c97.tar.gz rust-ca2639e82ec4a18d7359efbfb555ea69dd644c97.zip | |
Auto merge of #55014 - ljedrz:lazyboye_unwraps, r=matthewjasper
Prefer unwrap_or_else to unwrap_or in case of function calls/allocations The contents of `unwrap_or` are evaluated eagerly, so it's not a good pick in case of function calls and allocations. This PR also changes a few `unwrap_or`s with `unwrap_or_default`. An added bonus is that in some cases this change also reveals if the object it's called on is an `Option` or a `Result` (based on whether the closure takes an argument).
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/build.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/redox/args.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process/process_unix.rs | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 0831e29bddd..b3851d22841 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -97,8 +97,8 @@ fn build_libbacktrace(target: &str) -> Result<(), ()> { .file("../libbacktrace/sort.c") .file("../libbacktrace/state.c"); - let any_debug = env::var("RUSTC_DEBUGINFO").unwrap_or(String::new()) == "true" || - env::var("RUSTC_DEBUGINFO_LINES").unwrap_or(String::new()) == "true"; + let any_debug = env::var("RUSTC_DEBUGINFO").unwrap_or_default() == "true" || + env::var("RUSTC_DEBUGINFO_LINES").unwrap_or_default() == "true"; build.debug(any_debug); if target.contains("darwin") { diff --git a/src/libstd/sys/redox/args.rs b/src/libstd/sys/redox/args.rs index 556ed77372e..a7c8ade66f0 100644 --- a/src/libstd/sys/redox/args.rs +++ b/src/libstd/sys/redox/args.rs @@ -85,7 +85,7 @@ mod imp { } pub fn args() -> Args { - let bytes = clone().unwrap_or(Vec::new()); + let bytes = clone().unwrap_or_default(); let v: Vec<OsString> = bytes.into_iter().map(|v| { OsStringExt::from_vec(v) }).collect(); diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 9d6d607e3f3..7f1f9353c6d 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -331,7 +331,7 @@ impl Command { cvt(libc::posix_spawnattr_setflags(&mut attrs.0, flags as _))?; let envp = envp.map(|c| c.as_ptr()) - .unwrap_or(*sys::os::environ() as *const _); + .unwrap_or_else(|| *sys::os::environ() as *const _); let ret = libc::posix_spawnp( &mut p.pid, self.get_argv()[0], |
