diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 72ba5bbd5f2..444a9d4ba04 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -292,7 +292,7 @@ fn add_unreachable_coverage<'tcx>( if let Some(non_codegenned_file_name) = tcx.covered_file_name(non_codegenned_def_id) { let def_ids = unreachable_def_ids_by_file .entry(*non_codegenned_file_name) - .or_insert_with(|| Vec::new()); + .or_insert_with(Vec::new); def_ids.push(non_codegenned_def_id); } } diff --git a/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs b/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs index b0d7953f511..549b8d41f51 100644 --- a/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs +++ b/compiler/rustc_codegen_ssa/src/coverageinfo/map.rs @@ -170,30 +170,30 @@ impl<'tcx> FunctionCoverage<'tcx> { // `expression_index`s lower than the referencing `Expression`. Therefore, it is // reasonable to look up the new index of an expression operand while the `new_indexes` // vector is only complete up to the current `ExpressionIndex`. - let id_to_counter = - |new_indexes: &IndexVec>, - id: ExpressionOperandId| { - if id == ExpressionOperandId::ZERO { - Some(Counter::zero()) - } else if id.index() < self.counters.len() { - // Note: Some codegen-injected Counters may be only referenced by `Expression`s, - // and may not have their own `CodeRegion`s, - let index = CounterValueReference::from(id.index()); - Some(Counter::counter_value_reference(index)) - } else { - let index = self.expression_index(u32::from(id)); - self.expressions - .get(index) - .expect("expression id is out of range") - .as_ref() - // If an expression was optimized out, assume it would have produced a count - // of zero. This ensures that expressions dependent on optimized-out - // expressions are still valid. - .map_or(Some(Counter::zero()), |_| { - new_indexes[index].map(|new_index| Counter::expression(new_index)) - }) - } - }; + let id_to_counter = |new_indexes: &IndexVec< + InjectedExpressionIndex, + Option, + >, + id: ExpressionOperandId| { + if id == ExpressionOperandId::ZERO { + Some(Counter::zero()) + } else if id.index() < self.counters.len() { + // Note: Some codegen-injected Counters may be only referenced by `Expression`s, + // and may not have their own `CodeRegion`s, + let index = CounterValueReference::from(id.index()); + Some(Counter::counter_value_reference(index)) + } else { + let index = self.expression_index(u32::from(id)); + self.expressions + .get(index) + .expect("expression id is out of range") + .as_ref() + // If an expression was optimized out, assume it would have produced a count + // of zero. This ensures that expressions dependent on optimized-out + // expressions are still valid. + .map_or(Some(Counter::zero()), |_| new_indexes[index].map(Counter::expression)) + } + }; for (original_index, expression) in self.expressions.iter_enumerated().filter_map(|(original_index, entry)| { diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index 8afe94ac8db..372b077b5c0 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -198,7 +198,7 @@ impl Encodable for PackedFingerprint { impl Decodable for PackedFingerprint { #[inline] fn decode(d: &mut D) -> Result { - Fingerprint::decode(d).map(|f| PackedFingerprint(f)) + Fingerprint::decode(d).map(PackedFingerprint) } } diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs index 6993ce58fa6..f2345ff2707 100644 --- a/compiler/rustc_expand/src/tests.rs +++ b/compiler/rustc_expand/src/tests.rs @@ -92,7 +92,7 @@ crate fn matches_codepattern(a: &str, b: &str) -> bool { /// Advances the given peekable `Iterator` until it reaches a non-whitespace character. fn scan_for_non_ws_or_end>(iter: &mut Peekable) { - while iter.peek().copied().map(|c| rustc_lexer::is_whitespace(c)) == Some(true) { + while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) { iter.next(); } } diff --git a/compiler/rustc_graphviz/src/tests.rs b/compiler/rustc_graphviz/src/tests.rs index 055e13156ae..70b8197f5ef 100644 --- a/compiler/rustc_graphviz/src/tests.rs +++ b/compiler/rustc_graphviz/src/tests.rs @@ -55,7 +55,7 @@ impl NodeLabels<&'static str> { fn to_opt_strs(self) -> Vec> { match self { UnlabelledNodes(len) => vec![None; len], - AllNodesLabelled(lbls) => lbls.into_iter().map(|l| Some(l)).collect(), + AllNodesLabelled(lbls) => lbls.into_iter().map(Some).collect(), SomeNodesLabelled(lbls) => lbls.into_iter().collect(), } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 1fe1400fabe..a7e92ca6a77 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1429,22 +1429,21 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|value| PredicateAtom::RegionOutlives(value)) + self.map_bound(PredicateAtom::RegionOutlives) .potentially_quantified(tcx, PredicateKind::ForAll) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|value| PredicateAtom::TypeOutlives(value)) + self.map_bound(PredicateAtom::TypeOutlives) .potentially_quantified(tcx, PredicateKind::ForAll) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|value| PredicateAtom::Projection(value)) - .potentially_quantified(tcx, PredicateKind::ForAll) + self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll) } } diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir/src/transform/coverage/debug.rs index b66e37436a6..2cd0dc6b1f2 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir/src/transform/coverage/debug.rs @@ -130,7 +130,7 @@ const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS"; pub(super) fn debug_options<'a>() -> &'a DebugOptions { static DEBUG_OPTIONS: SyncOnceCell = SyncOnceCell::new(); - &DEBUG_OPTIONS.get_or_init(|| DebugOptions::from_env()) + &DEBUG_OPTIONS.get_or_init(DebugOptions::from_env) } /// Parses and maintains coverage-specific debug options captured from the environment variable @@ -430,7 +430,7 @@ impl GraphvizData { { bcb_to_coverage_spans_with_counters .entry(bcb) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .push((coverage_span.clone(), counter_kind.clone())); } } @@ -456,7 +456,7 @@ impl GraphvizData { if let Some(bcb_to_dependency_counters) = self.some_bcb_to_dependency_counters.as_mut() { bcb_to_dependency_counters .entry(bcb) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .push(counter_kind.clone()); } } @@ -527,8 +527,8 @@ impl UsedExpressions { pub fn add_expression_operands(&mut self, expression: &CoverageKind) { if let Some(used_expression_operands) = self.some_used_expression_operands.as_mut() { if let CoverageKind::Expression { id, lhs, rhs, .. } = *expression { - used_expression_operands.entry(lhs).or_insert_with(|| Vec::new()).push(id); - used_expression_operands.entry(rhs).or_insert_with(|| Vec::new()).push(id); + used_expression_operands.entry(lhs).or_insert_with(Vec::new).push(id); + used_expression_operands.entry(rhs).or_insert_with(Vec::new).push(id); } } } diff --git a/compiler/rustc_mir/src/transform/coverage/graph.rs b/compiler/rustc_mir/src/transform/coverage/graph.rs index b1a1bb957e7..e58b915f126 100644 --- a/compiler/rustc_mir/src/transform/coverage/graph.rs +++ b/compiler/rustc_mir/src/transform/coverage/graph.rs @@ -394,7 +394,7 @@ impl BasicCoverageBlockData { let operand = counter_kind.as_operand_id(); if let Some(replaced) = self .edge_from_bcbs - .get_or_insert_with(|| FxHashMap::default()) + .get_or_insert_with(FxHashMap::default) .insert(from_bcb, counter_kind) { Error::from_string(format!( diff --git a/compiler/rustc_span/src/analyze_source_file/tests.rs b/compiler/rustc_span/src/analyze_source_file/tests.rs index cb418a4bdaf..66aefc9a787 100644 --- a/compiler/rustc_span/src/analyze_source_file/tests.rs +++ b/compiler/rustc_span/src/analyze_source_file/tests.rs @@ -12,7 +12,7 @@ macro_rules! test { let (lines, multi_byte_chars, non_narrow_chars) = analyze_source_file($text, BytePos($source_file_start_pos)); - let expected_lines: Vec = $lines.into_iter().map(|pos| BytePos(pos)).collect(); + let expected_lines: Vec = $lines.into_iter().map(BytePos).collect(); assert_eq!(lines, expected_lines); diff --git a/compiler/rustc_span/src/lev_distance/tests.rs b/compiler/rustc_span/src/lev_distance/tests.rs index 7aa01cb8efe..90e20afc8f5 100644 --- a/compiler/rustc_span/src/lev_distance/tests.rs +++ b/compiler/rustc_span/src/lev_distance/tests.rs @@ -4,7 +4,7 @@ use super::*; fn test_lev_distance() { use std::char::{from_u32, MAX}; // Test bytelength agnosticity - for c in (0..MAX as u32).filter_map(|i| from_u32(i)).map(|i| i.to_string()) { + for c in (0..MAX as u32).filter_map(from_u32).map(|i| i.to_string()) { assert_eq!(lev_distance(&c[..], &c[..]), 0); } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 9a2210e4f0e..a48c35fbd1a 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1256,17 +1256,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }) }); - let regular_trait_predicates = existential_trait_refs.map(|trait_ref| { - trait_ref.map_bound(|trait_ref| ty::ExistentialPredicate::Trait(trait_ref)) - }); + let regular_trait_predicates = existential_trait_refs + .map(|trait_ref| trait_ref.map_bound(ty::ExistentialPredicate::Trait)); let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| { ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id())) }); let mut v = regular_trait_predicates .chain(auto_trait_predicates) .chain( - existential_projections - .map(|x| x.map_bound(|x| ty::ExistentialPredicate::Projection(x))), + existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)), ) .collect::>(); v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));