about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorljedrz <ljedrz@gmail.com>2018-10-12 16:16:00 +0200
committerljedrz <ljedrz@gmail.com>2018-10-19 09:45:45 +0200
commitd28aed6dc45ffccc790469cb04f3f775ddb2283a (patch)
treec1a3c356ba1ffc8173746e03f0f630ae4032624f /src/librustc
parentcb5e1b93e300cf9772a24c6de27d9f21cdae3123 (diff)
downloadrust-d28aed6dc45ffccc790469cb04f3f775ddb2283a.tar.gz
rust-d28aed6dc45ffccc790469cb04f3f775ddb2283a.zip
Prefer unwrap_or_else to unwrap_or in case of function calls/allocations
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/hir/lowering.rs2
-rw-r--r--src/librustc/lint/levels.rs2
-rw-r--r--src/librustc/lint/mod.rs2
-rw-r--r--src/librustc/traits/auto_trait.rs4
-rw-r--r--src/librustc/traits/error_reporting.rs4
-rw-r--r--src/librustc/ty/context.rs2
-rw-r--r--src/librustc/ty/query/on_disk_cache.rs2
7 files changed, 9 insertions, 9 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index e99d6502496..ad82d597849 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -1589,7 +1589,7 @@ impl<'a> LoweringContext<'a> {
 
         let resolution = self.resolver
             .get_resolution(id)
-            .unwrap_or(PathResolution::new(Def::Err));
+            .unwrap_or_else(|| PathResolution::new(Def::Err));
 
         let proj_start = p.segments.len() - resolution.unresolved_segments();
         let path = P(hir::Path {
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 950754a07ab..19eb127e6cc 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -97,7 +97,7 @@ impl LintLevelSets {
 
         // If `level` is none then we actually assume the default level for this
         // lint.
-        let mut level = level.unwrap_or(lint.default_level(sess));
+        let mut level = level.unwrap_or_else(|| lint.default_level(sess));
 
         // If we're about to issue a warning, check at the last minute for any
         // directives against the warnings "lint". If, for example, there's an
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index 3327b117d60..5ac0c0d32dc 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -519,7 +519,7 @@ impl LintBuffer {
     }
 
     pub fn take(&mut self, id: ast::NodeId) -> Vec<BufferedEarlyLint> {
-        self.map.remove(&id).unwrap_or(Vec::new())
+        self.map.remove(&id).unwrap_or_default()
     }
 
     pub fn get_any(&self) -> Option<&[BufferedEarlyLint]> {
diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs
index 1e5ce15914d..666e06a6464 100644
--- a/src/librustc/traits/auto_trait.rs
+++ b/src/librustc/traits/auto_trait.rs
@@ -498,8 +498,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
                     panic!("Missing lifetime with name {:?} for {:?}", name, region)
                 )
             )
-            .unwrap_or(&"'static".to_owned())
-            .clone()
+            .cloned()
+            .unwrap_or_else(|| "'static".to_owned())
     }
 
     // This is very similar to handle_lifetimes. However, instead of matching ty::Region's
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index db775beae4f..4ec9bfcce9e 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -352,7 +352,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
         obligation: &PredicateObligation<'tcx>,
     ) -> OnUnimplementedNote {
         let def_id = self.impl_similar_to(trait_ref, obligation)
-            .unwrap_or(trait_ref.def_id());
+            .unwrap_or_else(|| trait_ref.def_id());
         let trait_ref = *trait_ref.skip_binder();
 
         let mut flags = vec![];
@@ -639,7 +639,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                         let (post_message, pre_message) =
                             self.get_parent_trait_ref(&obligation.cause.code)
                                 .map(|t| (format!(" in `{}`", t), format!("within `{}`, ", t)))
-                            .unwrap_or((String::new(), String::new()));
+                            .unwrap_or_default();
 
                         let OnUnimplementedNote { message, label, note }
                             = self.on_unimplemented_note(trait_ref, obligation);
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 1bccd05af83..29474032ddc 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -565,7 +565,7 @@ impl<'tcx> TypeckTables<'tcx> {
 
     pub fn node_substs(&self, id: hir::HirId) -> &'tcx Substs<'tcx> {
         validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
-        self.node_substs.get(&id.local_id).cloned().unwrap_or(Substs::empty())
+        self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| Substs::empty())
     }
 
     pub fn node_substs_opt(&self, id: hir::HirId) -> Option<&'tcx Substs<'tcx>> {
diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs
index ce580c78033..368ec9bbaf5 100644
--- a/src/librustc/ty/query/on_disk_cache.rs
+++ b/src/librustc/ty/query/on_disk_cache.rs
@@ -342,7 +342,7 @@ impl<'sess> OnDiskCache<'sess> {
             &self.prev_diagnostics_index,
             "diagnostics");
 
-        diagnostics.unwrap_or(Vec::new())
+        diagnostics.unwrap_or_default()
     }
 
     /// Store a diagnostic emitted during the current compilation session.