Skip to content

Commit 9318810

Browse files
Rollup merge of #90652 - matthiaskrgr:unnnec_filter_map, r=jyn514
use filter(|x| matches!(..)) instead of filter_map(|x| match x ... => Some(xy))
2 parents f07f800 + ed7e438 commit 9318810

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
887887
let (lifetimes, binders): (FxIndexMap<hir::ParamName, Region>, Vec<_>) = c
888888
.generic_params
889889
.iter()
890-
.filter_map(|param| match param.kind {
891-
GenericParamKind::Lifetime { .. } => Some(param),
892-
_ => None,
893-
})
890+
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
894891
.enumerate()
895892
.map(|(late_bound_idx, param)| {
896893
let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param);
@@ -1370,9 +1367,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
13701367
let (lifetimes, binders): (FxIndexMap<hir::ParamName, Region>, Vec<_>) =
13711368
bound_generic_params
13721369
.iter()
1373-
.filter_map(|param| match param.kind {
1374-
GenericParamKind::Lifetime { .. } => Some(param),
1375-
_ => None,
1370+
.filter(|param| {
1371+
matches!(param.kind, GenericParamKind::Lifetime { .. })
13761372
})
13771373
.enumerate()
13781374
.map(|(late_bound_idx, param)| {
@@ -1469,10 +1465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
14691465
let binders_iter = trait_ref
14701466
.bound_generic_params
14711467
.iter()
1472-
.filter_map(|param| match param.kind {
1473-
GenericParamKind::Lifetime { .. } => Some(param),
1474-
_ => None,
1475-
})
1468+
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
14761469
.enumerate()
14771470
.map(|(late_bound_idx, param)| {
14781471
let pair = Region::late(
@@ -2235,19 +2228,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22352228
let binders: Vec<_> = generics
22362229
.params
22372230
.iter()
2238-
.filter_map(|param| match param.kind {
2239-
GenericParamKind::Lifetime { .. }
2240-
if self.map.late_bound.contains(&param.hir_id) =>
2241-
{
2242-
Some(param)
2243-
}
2244-
_ => None,
2231+
.filter(|param| {
2232+
matches!(param.kind, GenericParamKind::Lifetime { .. })
2233+
&& self.map.late_bound.contains(&param.hir_id)
22452234
})
22462235
.enumerate()
22472236
.map(|(late_bound_idx, param)| {
22482237
let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param);
2249-
let r = late_region_as_bound_region(self.tcx, &pair.1);
2250-
r
2238+
late_region_as_bound_region(self.tcx, &pair.1)
22512239
})
22522240
.collect();
22532241
self.map.late_bound_vars.insert(hir_id, binders);

compiler/rustc_typeck/src/coherence/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
180180

181181
let coerced_fields = fields
182182
.iter()
183-
.filter_map(|field| {
183+
.filter(|field| {
184184
let ty_a = field.ty(tcx, substs_a);
185185
let ty_b = field.ty(tcx, substs_b);
186186

187187
if let Ok(layout) = tcx.layout_of(param_env.and(ty_a)) {
188188
if layout.is_zst() && layout.align.abi.bytes() == 1 {
189189
// ignore ZST fields with alignment of 1 byte
190-
return None;
190+
return false;
191191
}
192192
}
193193

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

207-
return None;
207+
return false;
208208
}
209209
}
210210

211-
Some(field)
211+
return true;
212212
})
213213
.collect::<Vec<_>>();
214214

0 commit comments

Comments
 (0)