about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-20 11:22:48 +0000
committerbors <bors@rust-lang.org>2018-10-20 11:22:48 +0000
commitca2639e82ec4a18d7359efbfb555ea69dd644c97 (patch)
tree3dfa59589214b0157714150a785dd9cc4ccdc240 /src/librustc_codegen_llvm
parent94273f4d8e463cac45486328294bb1c2bbc10170 (diff)
parentd28aed6dc45ffccc790469cb04f3f775ddb2283a (diff)
downloadrust-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/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/attributes.rs2
-rw-r--r--src/librustc_codegen_llvm/back/rpath.rs2
-rw-r--r--src/librustc_codegen_llvm/llvm/archive_ro.rs2
-rw-r--r--src/librustc_codegen_llvm/llvm/diagnostic.rs2
4 files changed, 4 insertions, 4 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs
index a09a2b0fc4f..f45b3728bc1 100644
--- a/src/librustc_codegen_llvm/attributes.rs
+++ b/src/librustc_codegen_llvm/attributes.rs
@@ -154,7 +154,7 @@ pub fn from_fn_attrs(
     id: Option<DefId>,
 ) {
     let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
-        .unwrap_or(CodegenFnAttrs::new());
+        .unwrap_or_else(|| CodegenFnAttrs::new());
 
     inline(cx, llfn, codegen_fn_attrs.inline);
 
diff --git a/src/librustc_codegen_llvm/back/rpath.rs b/src/librustc_codegen_llvm/back/rpath.rs
index aa4f7688b0f..9609cb0c155 100644
--- a/src/librustc_codegen_llvm/back/rpath.rs
+++ b/src/librustc_codegen_llvm/back/rpath.rs
@@ -109,7 +109,7 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String
     };
 
     let cwd = env::current_dir().unwrap();
-    let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or(cwd.join(lib));
+    let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib));
     lib.pop();
     let mut output = cwd.join(&config.out_filename);
     output.pop();
diff --git a/src/librustc_codegen_llvm/llvm/archive_ro.rs b/src/librustc_codegen_llvm/llvm/archive_ro.rs
index e0a9f31e508..2a77f256e3a 100644
--- a/src/librustc_codegen_llvm/llvm/archive_ro.rs
+++ b/src/librustc_codegen_llvm/llvm/archive_ro.rs
@@ -40,7 +40,7 @@ impl ArchiveRO {
         return unsafe {
             let s = path2cstr(dst);
             let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
-                super::last_error().unwrap_or("failed to open archive".to_owned())
+                super::last_error().unwrap_or_else(|| "failed to open archive".to_owned())
             })?;
             Ok(ArchiveRO { raw: ar })
         };
diff --git a/src/librustc_codegen_llvm/llvm/diagnostic.rs b/src/librustc_codegen_llvm/llvm/diagnostic.rs
index c41a5f74ae3..b080c51c83a 100644
--- a/src/librustc_codegen_llvm/llvm/diagnostic.rs
+++ b/src/librustc_codegen_llvm/llvm/diagnostic.rs
@@ -77,7 +77,7 @@ impl OptimizationDiagnostic<'ll> {
             ).ok()
         ).ok();
 
-        let mut filename = filename.unwrap_or(String::new());
+        let mut filename = filename.unwrap_or_default();
         if filename.is_empty() {
             filename.push_str("<unknown file>");
         }