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 { if let ExprKind::Struct(_, ref efields, _) = init_struct.node {
for field in pfields { for field in pfields {
let name = field.node.ident.name; 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); check_pat(cx, &field.node.pat, efield, span, bindings);
} }
} else { } else {

View File

@ -58,10 +58,16 @@ pub fn get_attr<'a>(
attrs.iter().filter(move |attr| { attrs.iter().filter(move |attr| {
let attr_segments = &attr.path.segments; let attr_segments = &attr.path.segments;
if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" { if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
if let Some(deprecation_status) = BUILTIN_ATTRIBUTES if let Some(deprecation_status) =
.iter() BUILTIN_ATTRIBUTES
.find(|(builtin_name, _)| *builtin_name == attr_segments[1].ident.to_string()) .iter()
.map(|(_, deprecation_status)| deprecation_status) .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"); let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
match deprecation_status { 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(); let name = path.file_name()?.to_string_lossy();
// NOTE: This only handles a single dep // NOTE: This only handles a single dep
// https://github.com/laumann/compiletest-rs/issues/101 // https://github.com/laumann/compiletest-rs/issues/101
needs_disambiguation needs_disambiguation.iter().find_map(|dep| {
.iter() if name.starts_with(&format!("lib{}-", dep)) {
.find(|dep| name.starts_with(&format!("lib{}-", dep))) Some(format!("--extern {}={}", dep, path.display()))
.map(|dep| format!("--extern {}={}", dep, path.display())) } else {
None
}
})
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();