Update find(p).map(p) occurrences to use find_map(p)

This commit is contained in:
André Luis Leal Cardoso Junior 2019-04-28 15:19:05 -03:00
parent b411391f8e
commit e428862c95
3 changed files with 20 additions and 9 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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<_>>();