Skip to content

Commit 89cb411

Browse files
committed
rustc/infer: use unwrap_or(_else) where applicable
1 parent c222479 commit 89cb411

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/librustc/infer/canonical/query_result.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
135135
);
136136

137137
// Select everything, returning errors.
138-
let true_errors = match fulfill_cx.select_where_possible(self) {
139-
Ok(()) => vec![],
140-
Err(errors) => errors,
141-
};
138+
let true_errors = fulfill_cx.select_where_possible(self).err().unwrap_or_else(Vec::new);
142139
debug!("true_errors = {:#?}", true_errors);
143140

144141
if !true_errors.is_empty() {
@@ -148,10 +145,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
148145
}
149146

150147
// Anything left unselected *now* must be an ambiguity.
151-
let ambig_errors = match fulfill_cx.select_all_or_error(self) {
152-
Ok(()) => vec![],
153-
Err(errors) => errors,
154-
};
148+
let ambig_errors = fulfill_cx.select_all_or_error(self).err().unwrap_or_else(Vec::new);
155149
debug!("ambig_errors = {:#?}", ambig_errors);
156150

157151
let region_obligations = self.take_registered_region_obligations();
@@ -448,10 +442,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
448442
.variables
449443
.iter()
450444
.enumerate()
451-
.map(|(index, info)| match opt_values[CanonicalVar::new(index)] {
452-
Some(k) => k,
453-
None => self.fresh_inference_var_for_canonical_var(cause.span, *info),
454-
})
445+
.map(|(index, info)| opt_values[CanonicalVar::new(index)].unwrap_or_else(||
446+
self.fresh_inference_var_for_canonical_var(cause.span, *info)
447+
))
455448
.collect(),
456449
};
457450

src/librustc/infer/lexical_region_resolve/graphviz.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,9 @@ impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
187187
None => bug!("no node_id found for node: {:?}", n),
188188
};
189189
let name = || format!("node_{}", node_id);
190-
match dot::Id::new(name()) {
191-
Ok(id) => id,
192-
Err(_) => {
193-
bug!("failed to create graphviz node identified by {}", name());
194-
}
195-
}
190+
191+
dot::Id::new(name()).unwrap_or_else(|_|
192+
bug!("failed to create graphviz node identified by {}", name()))
196193
}
197194
fn node_label(&self, n: &Node) -> dot::LabelText {
198195
match *n {

0 commit comments

Comments
 (0)