Use .map() to modify data inside Options instead of using .and_then(|x| Some(y)) (clippy::option_and_then_some)

This commit is contained in:
Matthias Krüger 2020-03-04 15:13:19 +01:00
parent 07168f9cdc
commit 569676b9b0
4 changed files with 17 additions and 22 deletions

View File

@ -415,9 +415,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::ReferenceOutlivesReferent(ty) => {
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
}
super::ObjectTypeBound(ty, r) => tcx
.lift(&ty)
.and_then(|ty| tcx.lift(&r).and_then(|r| Some(super::ObjectTypeBound(ty, r)))),
super::ObjectTypeBound(ty, r) => {
tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
}
super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
super::Coercion { source, target } => {
Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })

View File

@ -37,7 +37,7 @@ impl<'a> Parser<'a> {
let inner_parse_policy = InnerAttributeParsePolicy::NotPermitted {
reason: inner_error_reason,
saw_doc_comment: just_parsed_doc_comment,
prev_attr_sp: attrs.last().and_then(|a| Some(a.span)),
prev_attr_sp: attrs.last().map(|a| a.span),
};
let attr = self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?;
attrs.push(attr);

View File

@ -1551,8 +1551,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let method_names = pcx.candidate_method_names();
pcx.allow_similar_names = false;
let applicable_close_candidates: Vec<ty::AssocItem> =
method_names
let applicable_close_candidates: Vec<ty::AssocItem> = method_names
.iter()
.filter_map(|&method_name| {
pcx.reset();
@ -1560,9 +1559,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
.map_or(None, |_| {
pcx.pick_core()
.and_then(|pick| pick.ok())
.and_then(|pick| Some(pick.item))
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
})
})
.collect();

View File

@ -121,9 +121,7 @@ pub fn external_generic_args(
let args: Vec<_> = substs
.iter()
.filter_map(|kind| match kind.unpack() {
GenericArgKind::Lifetime(lt) => {
lt.clean(cx).and_then(|lt| Some(GenericArg::Lifetime(lt)))
}
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
GenericArgKind::Type(_) if skip_self => {
skip_self = false;
None