Skip to content

Commit

Permalink
Update find(p).map(p) occurrences to use find_map(p)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Apr 30, 2019
1 parent b411391 commit e428862
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ fn check_pat<'a, 'tcx>(
if let ExprKind::Struct(_, ref efields, _) = init_struct.node {
for field in pfields {
let name = field.node.ident.name;
let efield = efields.iter().find(|f| f.ident.name == name).map(|f| &*f.expr);
let efield = efields
.iter()
.find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None });
check_pat(cx, &field.node.pat, efield, span, bindings);
}
} else {
Expand Down
14 changes: 10 additions & 4 deletions clippy_lints/src/utils/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ pub fn get_attr<'a>(
attrs.iter().filter(move |attr| {
let attr_segments = &attr.path.segments;
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
if let Some(deprecation_status) = BUILTIN_ATTRIBUTES
.iter()
.find(|(builtin_name, _)| *builtin_name == attr_segments[1].ident.to_string())
.map(|(_, deprecation_status)| deprecation_status)
if let Some(deprecation_status) =
BUILTIN_ATTRIBUTES
.iter()
.find_map(|(builtin_name, deprecation_status)| {
if *builtin_name == attr_segments[1].ident.to_string() {
Some(deprecation_status)
} else {
None
}
})
{
let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
match deprecation_status {
Expand Down
11 changes: 7 additions & 4 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
let name = path.file_name()?.to_string_lossy();
// NOTE: This only handles a single dep
// https://github.com/laumann/compiletest-rs/issues/101
needs_disambiguation
.iter()
.find(|dep| name.starts_with(&format!("lib{}-", dep)))
.map(|dep| format!("--extern {}={}", dep, path.display()))
needs_disambiguation.iter().find_map(|dep| {
if name.starts_with(&format!("lib{}-", dep)) {
Some(format!("--extern {}={}", dep, path.display()))
} else {
None
}
})
})
.collect::<Vec<_>>();

Expand Down

0 comments on commit e428862

Please sign in to comment.