Use Option::map instead of open coding it

This commit is contained in:
LingMan 2020-11-23 04:58:21 +01:00
parent c643dd2ec8
commit cd8973250d
3 changed files with 8 additions and 12 deletions

View file

@ -1152,10 +1152,7 @@ impl<'ll> MemberDescription<'ll> {
self.size.bits(), self.size.bits(),
self.align.bits() as u32, self.align.bits() as u32,
self.offset.bits(), self.offset.bits(),
match self.discriminant { self.discriminant.map(|v| cx.const_u64(v)),
None => None,
Some(value) => Some(cx.const_u64(value)),
},
self.flags, self.flags,
self.type_metadata, self.type_metadata,
) )

View file

@ -1106,10 +1106,7 @@ impl<T> Binder<T> {
impl<T> Binder<Option<T>> { impl<T> Binder<Option<T>> {
pub fn transpose(self) -> Option<Binder<T>> { pub fn transpose(self) -> Option<Binder<T>> {
match self.0 { self.0.map(Binder)
Some(v) => Some(Binder(v)),
None => None,
}
} }
} }

View file

@ -810,10 +810,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// can be given the suggestion "u32::from(x) > y" rather than // can be given the suggestion "u32::from(x) > y" rather than
// "x > y.try_into().unwrap()". // "x > y.try_into().unwrap()".
let lhs_expr_and_src = expected_ty_expr.and_then(|expr| { let lhs_expr_and_src = expected_ty_expr.and_then(|expr| {
match self.tcx.sess.source_map().span_to_snippet(expr.span).ok() { self.tcx
Some(src) => Some((expr, src)), .sess
None => None, .source_map()
} .span_to_snippet(expr.span)
.ok()
.map(|src| (expr, src))
}); });
let (span, msg, suggestion) = if let (Some((lhs_expr, lhs_src)), false) = let (span, msg, suggestion) = if let (Some((lhs_expr, lhs_src)), false) =
(lhs_expr_and_src, exp_to_found_is_fallible) (lhs_expr_and_src, exp_to_found_is_fallible)