Skip to content

Commit e428862

Browse files
committed
Update find(p).map(p) occurrences to use find_map(p)
1 parent b411391 commit e428862

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

clippy_lints/src/shadow.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ fn check_pat<'a, 'tcx>(
186186
if let ExprKind::Struct(_, ref efields, _) = init_struct.node {
187187
for field in pfields {
188188
let name = field.node.ident.name;
189-
let efield = efields.iter().find(|f| f.ident.name == name).map(|f| &*f.expr);
189+
let efield = efields
190+
.iter()
191+
.find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None });
190192
check_pat(cx, &field.node.pat, efield, span, bindings);
191193
}
192194
} else {

clippy_lints/src/utils/attrs.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ pub fn get_attr<'a>(
5858
attrs.iter().filter(move |attr| {
5959
let attr_segments = &attr.path.segments;
6060
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
61-
if let Some(deprecation_status) = BUILTIN_ATTRIBUTES
62-
.iter()
63-
.find(|(builtin_name, _)| *builtin_name == attr_segments[1].ident.to_string())
64-
.map(|(_, deprecation_status)| deprecation_status)
61+
if let Some(deprecation_status) =
62+
BUILTIN_ATTRIBUTES
63+
.iter()
64+
.find_map(|(builtin_name, deprecation_status)| {
65+
if *builtin_name == attr_segments[1].ident.to_string() {
66+
Some(deprecation_status)
67+
} else {
68+
None
69+
}
70+
})
6571
{
6672
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
6773
match deprecation_status {

tests/compile-test.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
6161
let name = path.file_name()?.to_string_lossy();
6262
// NOTE: This only handles a single dep
6363
// https://github.com/laumann/compiletest-rs/issues/101
64-
needs_disambiguation
65-
.iter()
66-
.find(|dep| name.starts_with(&format!("lib{}-", dep)))
67-
.map(|dep| format!("--extern {}={}", dep, path.display()))
64+
needs_disambiguation.iter().find_map(|dep| {
65+
if name.starts_with(&format!("lib{}-", dep)) {
66+
Some(format!("--extern {}={}", dep, path.display()))
67+
} else {
68+
None
69+
}
70+
})
6871
})
6972
.collect::<Vec<_>>();
7073

0 commit comments

Comments
 (0)