Skip to content

Commit 14d8112

Browse files
refactor: use .find().and_then()
Co-authored-by: Samuel Tardieu <[email protected]>
1 parent 283f684 commit 14d8112

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

clippy_lints/src/methods/concealed_obvious_default.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,17 @@ pub(super) fn check(cx: &LateContext<'_>, recv: &hir::Expr<'_>, method_name: Sym
2222
if let ty::Adt(adt, generic_args) = recv_ty.kind()
2323
// `name_of_generic`, is e.g. a `sym::Option`
2424
&& let Some(name_of_generic) = cx.tcx.get_diagnostic_name(adt.did())
25-
&& let Some((message, suggestion)) = CONCEALING_METHODS.into_iter().find_map(|concealing| {
26-
(name_of_generic == concealing.ty && method_name == concealing.method)
27-
.then(|| {
28-
generic_args.get(concealing.generic_index).and_then(|entry| {
29-
entry.as_type().and_then(|ty| {
30-
extract_obvious_default(cx, ty).map(|(default, ty)| {
31-
let method = (concealing.fmt_msg)(ty);
32-
(
33-
format!("method {method} conceals the underlying type"),
34-
(concealing.fmt_sugg)(default),
35-
)
36-
})
37-
})
38-
})
39-
})
40-
.flatten()
25+
&& let Some((message, suggestion)) = CONCEALING_METHODS.into_iter().find(|concealing| {
26+
name_of_generic == concealing.ty && method_name == concealing.method
27+
}).and_then(|concealing| {
28+
let ty = generic_args.type_at(concealing.generic_index);
29+
extract_obvious_default(cx, ty).map(|(default, ty)| {
30+
let method = (concealing.fmt_msg)(ty);
31+
(
32+
format!("method {method} conceals the underlying type"),
33+
(concealing.fmt_sugg)(default),
34+
)
35+
})
4136
})
4237
{
4338
span_lint_and_sugg(

0 commit comments

Comments
 (0)