about summary refs log tree commit diff
diff options
context:
space:
mode:
authorljedrz <ljedrz@gmail.com>2018-09-28 17:20:37 +0200
committerljedrz <ljedrz@gmail.com>2018-09-29 14:57:35 +0200
commit89cb4119434ec8b013b2240073276c9a42460e05 (patch)
treebf114c6c0e1334933931bf34aa27b83c9d5ecdc8
parentc222479c6feb036e5e5198e068aa9824d855ffa4 (diff)
downloadrust-89cb4119434ec8b013b2240073276c9a42460e05.tar.gz
rust-89cb4119434ec8b013b2240073276c9a42460e05.zip
rustc/infer: use unwrap_or(_else) where applicable
-rw-r--r--src/librustc/infer/canonical/query_result.rs17
-rw-r--r--src/librustc/infer/lexical_region_resolve/graphviz.rs9
2 files changed, 8 insertions, 18 deletions
diff --git a/src/librustc/infer/canonical/query_result.rs b/src/librustc/infer/canonical/query_result.rs
index 65d42c0888d..810d3231acd 100644
--- a/src/librustc/infer/canonical/query_result.rs
+++ b/src/librustc/infer/canonical/query_result.rs
@@ -135,10 +135,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
         );
 
         // Select everything, returning errors.
-        let true_errors = match fulfill_cx.select_where_possible(self) {
-            Ok(()) => vec![],
-            Err(errors) => errors,
-        };
+        let true_errors = fulfill_cx.select_where_possible(self).err().unwrap_or_else(Vec::new);
         debug!("true_errors = {:#?}", true_errors);
 
         if !true_errors.is_empty() {
@@ -148,10 +145,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
         }
 
         // Anything left unselected *now* must be an ambiguity.
-        let ambig_errors = match fulfill_cx.select_all_or_error(self) {
-            Ok(()) => vec![],
-            Err(errors) => errors,
-        };
+        let ambig_errors = fulfill_cx.select_all_or_error(self).err().unwrap_or_else(Vec::new);
         debug!("ambig_errors = {:#?}", ambig_errors);
 
         let region_obligations = self.take_registered_region_obligations();
@@ -448,10 +442,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
                 .variables
                 .iter()
                 .enumerate()
-                .map(|(index, info)| match opt_values[CanonicalVar::new(index)] {
-                    Some(k) => k,
-                    None => self.fresh_inference_var_for_canonical_var(cause.span, *info),
-                })
+                .map(|(index, info)| opt_values[CanonicalVar::new(index)].unwrap_or_else(||
+                    self.fresh_inference_var_for_canonical_var(cause.span, *info)
+                ))
                 .collect(),
         };
 
diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs
index bdd3f78aff3..f605da584b2 100644
--- a/src/librustc/infer/lexical_region_resolve/graphviz.rs
+++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs
@@ -187,12 +187,9 @@ impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
             None => bug!("no node_id found for node: {:?}", n),
         };
         let name = || format!("node_{}", node_id);
-        match dot::Id::new(name()) {
-            Ok(id) => id,
-            Err(_) => {
-                bug!("failed to create graphviz node identified by {}", name());
-            }
-        }
+
+        dot::Id::new(name()).unwrap_or_else(|_|
+            bug!("failed to create graphviz node identified by {}", name()))
     }
     fn node_label(&self, n: &Node) -> dot::LabelText {
         match *n {