Skip to content

Commit 569676b

Browse files
committed
Use .map() to modify data inside Options instead of using .and_then(|x| Some(y)) (clippy::option_and_then_some)
1 parent 07168f9 commit 569676b

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

src/librustc/traits/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
415415
super::ReferenceOutlivesReferent(ty) => {
416416
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
417417
}
418-
super::ObjectTypeBound(ty, r) => tcx
419-
.lift(&ty)
420-
.and_then(|ty| tcx.lift(&r).and_then(|r| Some(super::ObjectTypeBound(ty, r)))),
418+
super::ObjectTypeBound(ty, r) => {
419+
tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
420+
}
421421
super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
422422
super::Coercion { source, target } => {
423423
Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })

src/librustc_parse/parser/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> Parser<'a> {
3737
let inner_parse_policy = InnerAttributeParsePolicy::NotPermitted {
3838
reason: inner_error_reason,
3939
saw_doc_comment: just_parsed_doc_comment,
40-
prev_attr_sp: attrs.last().and_then(|a| Some(a.span)),
40+
prev_attr_sp: attrs.last().map(|a| a.span),
4141
};
4242
let attr = self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?;
4343
attrs.push(attr);

src/librustc_typeck/check/method/probe.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -1551,21 +1551,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15511551

15521552
let method_names = pcx.candidate_method_names();
15531553
pcx.allow_similar_names = false;
1554-
let applicable_close_candidates: Vec<ty::AssocItem> =
1555-
method_names
1556-
.iter()
1557-
.filter_map(|&method_name| {
1558-
pcx.reset();
1559-
pcx.method_name = Some(method_name);
1560-
pcx.assemble_inherent_candidates();
1561-
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
1562-
.map_or(None, |_| {
1563-
pcx.pick_core()
1564-
.and_then(|pick| pick.ok())
1565-
.and_then(|pick| Some(pick.item))
1566-
})
1567-
})
1568-
.collect();
1554+
let applicable_close_candidates: Vec<ty::AssocItem> = method_names
1555+
.iter()
1556+
.filter_map(|&method_name| {
1557+
pcx.reset();
1558+
pcx.method_name = Some(method_name);
1559+
pcx.assemble_inherent_candidates();
1560+
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
1561+
.map_or(None, |_| {
1562+
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
1563+
})
1564+
})
1565+
.collect();
15691566

15701567
if applicable_close_candidates.is_empty() {
15711568
Ok(None)

src/librustdoc/clean/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ pub fn external_generic_args(
121121
let args: Vec<_> = substs
122122
.iter()
123123
.filter_map(|kind| match kind.unpack() {
124-
GenericArgKind::Lifetime(lt) => {
125-
lt.clean(cx).and_then(|lt| Some(GenericArg::Lifetime(lt)))
126-
}
124+
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
127125
GenericArgKind::Type(_) if skip_self => {
128126
skip_self = false;
129127
None

0 commit comments

Comments
 (0)