Skip to content

Commit e2272cd

Browse files
committed
remove redundant closures (clippy::redundant_closure)
1 parent 18cb4ad commit e2272cd

File tree

11 files changed

+42
-45
lines changed

11 files changed

+42
-45
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn add_unreachable_coverage<'tcx>(
292292
if let Some(non_codegenned_file_name) = tcx.covered_file_name(non_codegenned_def_id) {
293293
let def_ids = unreachable_def_ids_by_file
294294
.entry(*non_codegenned_file_name)
295-
.or_insert_with(|| Vec::new());
295+
.or_insert_with(Vec::new);
296296
def_ids.push(non_codegenned_def_id);
297297
}
298298
}

compiler/rustc_codegen_ssa/src/coverageinfo/map.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,30 @@ impl<'tcx> FunctionCoverage<'tcx> {
170170
// `expression_index`s lower than the referencing `Expression`. Therefore, it is
171171
// reasonable to look up the new index of an expression operand while the `new_indexes`
172172
// vector is only complete up to the current `ExpressionIndex`.
173-
let id_to_counter =
174-
|new_indexes: &IndexVec<InjectedExpressionIndex, Option<MappedExpressionIndex>>,
175-
id: ExpressionOperandId| {
176-
if id == ExpressionOperandId::ZERO {
177-
Some(Counter::zero())
178-
} else if id.index() < self.counters.len() {
179-
// Note: Some codegen-injected Counters may be only referenced by `Expression`s,
180-
// and may not have their own `CodeRegion`s,
181-
let index = CounterValueReference::from(id.index());
182-
Some(Counter::counter_value_reference(index))
183-
} else {
184-
let index = self.expression_index(u32::from(id));
185-
self.expressions
186-
.get(index)
187-
.expect("expression id is out of range")
188-
.as_ref()
189-
// If an expression was optimized out, assume it would have produced a count
190-
// of zero. This ensures that expressions dependent on optimized-out
191-
// expressions are still valid.
192-
.map_or(Some(Counter::zero()), |_| {
193-
new_indexes[index].map(|new_index| Counter::expression(new_index))
194-
})
195-
}
196-
};
173+
let id_to_counter = |new_indexes: &IndexVec<
174+
InjectedExpressionIndex,
175+
Option<MappedExpressionIndex>,
176+
>,
177+
id: ExpressionOperandId| {
178+
if id == ExpressionOperandId::ZERO {
179+
Some(Counter::zero())
180+
} else if id.index() < self.counters.len() {
181+
// Note: Some codegen-injected Counters may be only referenced by `Expression`s,
182+
// and may not have their own `CodeRegion`s,
183+
let index = CounterValueReference::from(id.index());
184+
Some(Counter::counter_value_reference(index))
185+
} else {
186+
let index = self.expression_index(u32::from(id));
187+
self.expressions
188+
.get(index)
189+
.expect("expression id is out of range")
190+
.as_ref()
191+
// If an expression was optimized out, assume it would have produced a count
192+
// of zero. This ensures that expressions dependent on optimized-out
193+
// expressions are still valid.
194+
.map_or(Some(Counter::zero()), |_| new_indexes[index].map(Counter::expression))
195+
}
196+
};
197197

198198
for (original_index, expression) in
199199
self.expressions.iter_enumerated().filter_map(|(original_index, entry)| {

compiler/rustc_data_structures/src/fingerprint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<E: rustc_serialize::Encoder> Encodable<E> for PackedFingerprint {
198198
impl<D: rustc_serialize::Decoder> Decodable<D> for PackedFingerprint {
199199
#[inline]
200200
fn decode(d: &mut D) -> Result<Self, D::Error> {
201-
Fingerprint::decode(d).map(|f| PackedFingerprint(f))
201+
Fingerprint::decode(d).map(PackedFingerprint)
202202
}
203203
}
204204

compiler/rustc_expand/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ crate fn matches_codepattern(a: &str, b: &str) -> bool {
9292

9393
/// Advances the given peekable `Iterator` until it reaches a non-whitespace character.
9494
fn scan_for_non_ws_or_end<I: Iterator<Item = char>>(iter: &mut Peekable<I>) {
95-
while iter.peek().copied().map(|c| rustc_lexer::is_whitespace(c)) == Some(true) {
95+
while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) {
9696
iter.next();
9797
}
9898
}

compiler/rustc_graphviz/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl NodeLabels<&'static str> {
5555
fn to_opt_strs(self) -> Vec<Option<&'static str>> {
5656
match self {
5757
UnlabelledNodes(len) => vec![None; len],
58-
AllNodesLabelled(lbls) => lbls.into_iter().map(|l| Some(l)).collect(),
58+
AllNodesLabelled(lbls) => lbls.into_iter().map(Some).collect(),
5959
SomeNodesLabelled(lbls) => lbls.into_iter().collect(),
6060
}
6161
}

compiler/rustc_middle/src/ty/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1429,22 +1429,21 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
14291429

14301430
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
14311431
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1432-
self.map_bound(|value| PredicateAtom::RegionOutlives(value))
1432+
self.map_bound(PredicateAtom::RegionOutlives)
14331433
.potentially_quantified(tcx, PredicateKind::ForAll)
14341434
}
14351435
}
14361436

14371437
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
14381438
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1439-
self.map_bound(|value| PredicateAtom::TypeOutlives(value))
1439+
self.map_bound(PredicateAtom::TypeOutlives)
14401440
.potentially_quantified(tcx, PredicateKind::ForAll)
14411441
}
14421442
}
14431443

14441444
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14451445
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1446-
self.map_bound(|value| PredicateAtom::Projection(value))
1447-
.potentially_quantified(tcx, PredicateKind::ForAll)
1446+
self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll)
14481447
}
14491448
}
14501449

compiler/rustc_mir/src/transform/coverage/debug.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS";
130130
pub(super) fn debug_options<'a>() -> &'a DebugOptions {
131131
static DEBUG_OPTIONS: SyncOnceCell<DebugOptions> = SyncOnceCell::new();
132132

133-
&DEBUG_OPTIONS.get_or_init(|| DebugOptions::from_env())
133+
&DEBUG_OPTIONS.get_or_init(DebugOptions::from_env)
134134
}
135135

136136
/// Parses and maintains coverage-specific debug options captured from the environment variable
@@ -430,7 +430,7 @@ impl GraphvizData {
430430
{
431431
bcb_to_coverage_spans_with_counters
432432
.entry(bcb)
433-
.or_insert_with(|| Vec::new())
433+
.or_insert_with(Vec::new)
434434
.push((coverage_span.clone(), counter_kind.clone()));
435435
}
436436
}
@@ -456,7 +456,7 @@ impl GraphvizData {
456456
if let Some(bcb_to_dependency_counters) = self.some_bcb_to_dependency_counters.as_mut() {
457457
bcb_to_dependency_counters
458458
.entry(bcb)
459-
.or_insert_with(|| Vec::new())
459+
.or_insert_with(Vec::new)
460460
.push(counter_kind.clone());
461461
}
462462
}
@@ -527,8 +527,8 @@ impl UsedExpressions {
527527
pub fn add_expression_operands(&mut self, expression: &CoverageKind) {
528528
if let Some(used_expression_operands) = self.some_used_expression_operands.as_mut() {
529529
if let CoverageKind::Expression { id, lhs, rhs, .. } = *expression {
530-
used_expression_operands.entry(lhs).or_insert_with(|| Vec::new()).push(id);
531-
used_expression_operands.entry(rhs).or_insert_with(|| Vec::new()).push(id);
530+
used_expression_operands.entry(lhs).or_insert_with(Vec::new).push(id);
531+
used_expression_operands.entry(rhs).or_insert_with(Vec::new).push(id);
532532
}
533533
}
534534
}

compiler/rustc_mir/src/transform/coverage/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl BasicCoverageBlockData {
394394
let operand = counter_kind.as_operand_id();
395395
if let Some(replaced) = self
396396
.edge_from_bcbs
397-
.get_or_insert_with(|| FxHashMap::default())
397+
.get_or_insert_with(FxHashMap::default)
398398
.insert(from_bcb, counter_kind)
399399
{
400400
Error::from_string(format!(

compiler/rustc_span/src/analyze_source_file/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ macro_rules! test {
1212
let (lines, multi_byte_chars, non_narrow_chars) =
1313
analyze_source_file($text, BytePos($source_file_start_pos));
1414

15-
let expected_lines: Vec<BytePos> = $lines.into_iter().map(|pos| BytePos(pos)).collect();
15+
let expected_lines: Vec<BytePos> = $lines.into_iter().map(BytePos).collect();
1616

1717
assert_eq!(lines, expected_lines);
1818

compiler/rustc_span/src/lev_distance/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
fn test_lev_distance() {
55
use std::char::{from_u32, MAX};
66
// Test bytelength agnosticity
7-
for c in (0..MAX as u32).filter_map(|i| from_u32(i)).map(|i| i.to_string()) {
7+
for c in (0..MAX as u32).filter_map(from_u32).map(|i| i.to_string()) {
88
assert_eq!(lev_distance(&c[..], &c[..]), 0);
99
}
1010

compiler/rustc_typeck/src/astconv/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1256,17 +1256,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12561256
})
12571257
});
12581258

1259-
let regular_trait_predicates = existential_trait_refs.map(|trait_ref| {
1260-
trait_ref.map_bound(|trait_ref| ty::ExistentialPredicate::Trait(trait_ref))
1261-
});
1259+
let regular_trait_predicates = existential_trait_refs
1260+
.map(|trait_ref| trait_ref.map_bound(ty::ExistentialPredicate::Trait));
12621261
let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| {
12631262
ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id()))
12641263
});
12651264
let mut v = regular_trait_predicates
12661265
.chain(auto_trait_predicates)
12671266
.chain(
1268-
existential_projections
1269-
.map(|x| x.map_bound(|x| ty::ExistentialPredicate::Projection(x))),
1267+
existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)),
12701268
)
12711269
.collect::<SmallVec<[_; 8]>>();
12721270
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));

0 commit comments

Comments
 (0)