Skip to content

Commit

Permalink
Rollup merge of rust-lang#90652 - matthiaskrgr:unnnec_filter_map, r=j…
Browse files Browse the repository at this point in the history
…yn514

use filter(|x| matches!(..)) instead of filter_map(|x| match x ... => Some(xy))
  • Loading branch information
matthiaskrgr authored Nov 8, 2021
2 parents 1eebe3e + ed7e438 commit 21554e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
28 changes: 8 additions & 20 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let (lifetimes, binders): (FxIndexMap<hir::ParamName, Region>, Vec<_>) = c
.generic_params
.iter()
.filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => Some(param),
_ => None,
})
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate()
.map(|(late_bound_idx, param)| {
let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param);
Expand Down Expand Up @@ -1370,9 +1367,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let (lifetimes, binders): (FxIndexMap<hir::ParamName, Region>, Vec<_>) =
bound_generic_params
.iter()
.filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => Some(param),
_ => None,
.filter(|param| {
matches!(param.kind, GenericParamKind::Lifetime { .. })
})
.enumerate()
.map(|(late_bound_idx, param)| {
Expand Down Expand Up @@ -1469,10 +1465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let binders_iter = trait_ref
.bound_generic_params
.iter()
.filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => Some(param),
_ => None,
})
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate()
.map(|(late_bound_idx, param)| {
let pair = Region::late(
Expand Down Expand Up @@ -2235,19 +2228,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let binders: Vec<_> = generics
.params
.iter()
.filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. }
if self.map.late_bound.contains(&param.hir_id) =>
{
Some(param)
}
_ => None,
.filter(|param| {
matches!(param.kind, GenericParamKind::Lifetime { .. })
&& self.map.late_bound.contains(&param.hir_id)
})
.enumerate()
.map(|(late_bound_idx, param)| {
let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param);
let r = late_region_as_bound_region(self.tcx, &pair.1);
r
late_region_as_bound_region(self.tcx, &pair.1)
})
.collect();
self.map.late_bound_vars.insert(hir_id, binders);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef

let coerced_fields = fields
.iter()
.filter_map(|field| {
.filter(|field| {
let ty_a = field.ty(tcx, substs_a);
let ty_b = field.ty(tcx, substs_b);

if let Ok(layout) = tcx.layout_of(param_env.and(ty_a)) {
if layout.is_zst() && layout.align.abi.bytes() == 1 {
// ignore ZST fields with alignment of 1 byte
return None;
return false;
}
}

Expand All @@ -204,11 +204,11 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
))
.emit();

return None;
return false;
}
}

Some(field)
return true;
})
.collect::<Vec<_>>();

Expand Down

0 comments on commit 21554e6

Please sign in to comment.