Skip to content

Commit f063531

Browse files
authored
Rollup merge of rust-lang#70269 - matthiaskrgr:clippy_closures, r=Dylan-DPC
remove redundant closures (clippy::redundant_closure)
2 parents 390088c + 263cbd1 commit f063531

File tree

22 files changed

+33
-41
lines changed

22 files changed

+33
-41
lines changed

src/liballoc/collections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
196196
(root, length)
197197
};
198198

199-
out_node.push(k, v, subroot.unwrap_or_else(|| node::Root::new_leaf()));
199+
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
200200
out_tree.length += 1 + sublength;
201201
}
202202
}
@@ -2147,7 +2147,7 @@ impl<K, V> BTreeMap<K, V> {
21472147
/// If the root node is the empty (non-allocated) root node, allocate our
21482148
/// own node.
21492149
fn ensure_root_is_owned(&mut self) -> &mut node::Root<K, V> {
2150-
self.root.get_or_insert_with(|| node::Root::new_leaf())
2150+
self.root.get_or_insert_with(node::Root::new_leaf)
21512151
}
21522152
}
21532153

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl DepGraph {
245245
C: DepGraphSafe + StableHashingContextProvider<'a>,
246246
{
247247
if let Some(ref data) = self.data {
248-
let task_deps = create_task(key).map(|deps| Lock::new(deps));
248+
let task_deps = create_task(key).map(Lock::new);
249249

250250
// In incremental mode, hash the result of the task. We don't
251251
// do anything with the hash yet, but we are computing it

src/librustc/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl UndefMask {
796796
}
797797

798798
// FIXME(oli-obk): optimize this for allocations larger than a block.
799-
let idx = (start.bytes()..end.bytes()).map(|i| Size::from_bytes(i)).find(|&i| !self.get(i));
799+
let idx = (start.bytes()..end.bytes()).map(Size::from_bytes).find(|&i| !self.get(i));
800800

801801
match idx {
802802
Some(idx) => Err(idx),

src/librustc_ast/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl ParenthesizedArgs {
250250
pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
251251
AngleBracketedArgs {
252252
span: self.span,
253-
args: self.inputs.iter().cloned().map(|input| GenericArg::Type(input)).collect(),
253+
args: self.inputs.iter().cloned().map(GenericArg::Type).collect(),
254254
constraints: vec![],
255255
}
256256
}

src/librustc_ast_lowering/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
272272
if !generic_args.parenthesized && !has_lifetimes {
273273
generic_args.args = self
274274
.elided_path_lifetimes(path_span, expected_lifetimes)
275-
.map(|lt| GenericArg::Lifetime(lt))
275+
.map(GenericArg::Lifetime)
276276
.chain(generic_args.args.into_iter())
277277
.collect();
278278
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {

src/librustc_builtin_macros/deriving/generic/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<'a> Path<'a> {
7676
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
7777
let params = lt
7878
.into_iter()
79-
.map(|lt| GenericArg::Lifetime(lt))
80-
.chain(tys.into_iter().map(|ty| GenericArg::Type(ty)))
79+
.map(GenericArg::Lifetime)
80+
.chain(tys.into_iter().map(GenericArg::Type))
8181
.collect();
8282

8383
match self.kind {

src/librustc_data_structures/sharded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct Sharded<T> {
3030
impl<T: Default> Default for Sharded<T> {
3131
#[inline]
3232
fn default() -> Self {
33-
Self::new(|| T::default())
33+
Self::new(T::default)
3434
}
3535
}
3636

src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a> DiagnosticBuilder<'a> {
162162
message: &str,
163163
span: Option<S>,
164164
) -> &mut Self {
165-
let span = span.map(|s| s.into()).unwrap_or_else(|| MultiSpan::new());
165+
let span = span.map(|s| s.into()).unwrap_or_else(MultiSpan::new);
166166
self.0.diagnostic.sub(level, message, span, None);
167167
self
168168
}

src/librustc_feature/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Feature {
5151

5252
impl Feature {
5353
fn issue(&self) -> Option<NonZeroU32> {
54-
self.issue.and_then(|i| NonZeroU32::new(i))
54+
self.issue.and_then(NonZeroU32::new)
5555
}
5656
}
5757

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl<'tcx> QueryContext<'tcx> {
703703
where
704704
F: FnOnce(TyCtxt<'tcx>) -> R,
705705
{
706-
ty::tls::enter_global(self.0, |tcx| f(tcx))
706+
ty::tls::enter_global(self.0, f)
707707
}
708708

709709
pub fn print_stats(&mut self) {

src/librustc_metadata/locator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a> CrateLocator<'a> {
327327
.into_iter()
328328
.filter_map(|entry| entry.files())
329329
.flatten()
330-
.map(|location| PathBuf::from(location))
330+
.map(PathBuf::from)
331331
.collect()
332332
} else {
333333
// SVH being specified means this is a transitive dependency,

src/librustc_mir/dataflow/generic/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn write_diff<A: Analysis<'tcx>>(
577577
let mut clear = HybridBitSet::new_empty(len);
578578

579579
// FIXME: Implement a lazy iterator over the symmetric difference of two bitsets.
580-
for i in (0..len).map(|i| A::Idx::new(i)) {
580+
for i in (0..len).map(A::Idx::new) {
581581
match (from.contains(i), to.contains(i)) {
582582
(false, true) => set.insert(i),
583583
(true, false) => clear.insert(i),

src/librustc_mir/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
895895
.unwrap()
896896
})
897897
.filter(|&instance| should_monomorphize_locally(tcx, &instance))
898-
.map(|instance| create_fn_mono_item(instance));
898+
.map(create_fn_mono_item);
899899
output.extend(methods);
900900
}
901901

src/librustc_mir_build/hair/pattern/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ fn split_grouped_constructors<'p, 'tcx>(
20662066
}
20672067
intersection
20682068
})
2069-
.flat_map(|range| range_borders(range));
2069+
.flat_map(range_borders);
20702070
let ctor_borders = range_borders(ctor_range.clone());
20712071
let mut borders: Vec<_> = row_borders.chain(ctor_borders).collect();
20722072
borders.sort_unstable();

src/librustc_save_analysis/dump_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11481148

11491149
let sub_span = path.segments.last().unwrap().ident.span;
11501150
if !self.span.filter_generated(sub_span) {
1151-
let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id));
1151+
let ref_id = self.lookup_def_id(id).map(id_from_def_id);
11521152
let alias_span = alias.map(|i| self.span_from_span(i.span));
11531153
let span = self.span_from_span(sub_span);
11541154
self.dumper.import(

src/librustc_save_analysis/lib.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
326326
.as_ref()
327327
.and_then(|t| self.lookup_def_id(t.ref_id))
328328
.map(id_from_def_id)
329-
.unwrap_or_else(|| null_id()),
329+
.unwrap_or_else(null_id),
330330
},
331331
Impl {
332332
id: impl_id,
@@ -487,9 +487,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
487487
qualname,
488488
// FIXME you get better data here by using the visitor.
489489
value: String::new(),
490-
parent: parent_scope.map(|id| id_from_def_id(id)),
490+
parent: parent_scope.map(id_from_def_id),
491491
children: vec![],
492-
decl_id: decl_id.map(|id| id_from_def_id(id)),
492+
decl_id: decl_id.map(id_from_def_id),
493493
docs,
494494
sig: None,
495495
attributes: lower_attributes(attributes, self),
@@ -541,7 +541,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
541541
.tcx
542542
.find_field_index(ident, variant)
543543
.map(|index| id_from_def_id(variant.fields[index].did))
544-
.unwrap_or_else(|| null_id()),
544+
.unwrap_or_else(null_id),
545545
}))
546546
}
547547
ty::Tuple(..) => None,
@@ -590,14 +590,11 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
590590
Some(Data::RefData(Ref {
591591
kind: RefKind::Function,
592592
span,
593-
ref_id: def_id
594-
.or(decl_id)
595-
.map(|id| id_from_def_id(id))
596-
.unwrap_or_else(|| null_id()),
593+
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(|| null_id()),
597594
}))
598595
}
599596
ast::ExprKind::Path(_, ref path) => {
600-
self.get_path_data(expr.id, path).map(|d| Data::RefData(d))
597+
self.get_path_data(expr.id, path).map(Data::RefData)
601598
}
602599
_ => {
603600
// FIXME
@@ -1075,7 +1072,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
10751072

10761073
fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
10771074
let def_id = scx.tcx.hir().opt_local_def_id_from_node_id(id);
1078-
def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| {
1075+
def_id.map(id_from_def_id).unwrap_or_else(|| {
10791076
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
10801077
// out of the maximum u32 value. This will work unless you have *billions*
10811078
// of definitions in a single crate (very unlikely to actually happen).

src/librustc_session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ fn select_incremental_path(
13101310
(None, Some(path)) => Some(path),
13111311
(None, None) => None,
13121312
}
1313-
.map(|m| PathBuf::from(m))
1313+
.map(PathBuf::from)
13141314
}
13151315

13161316
fn collect_print_requests(

src/librustc_trait_selection/traits/fulfill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
131131
// FIXME: if we kept the original cache key, we could mark projection
132132
// obligations as complete for the projection cache here.
133133

134-
errors.extend(outcome.errors.into_iter().map(|e| to_fulfillment_error(e)));
134+
errors.extend(outcome.errors.into_iter().map(to_fulfillment_error));
135135

136136
// If nothing new was added, no need to keep looping.
137137
if outcome.stalled {
@@ -214,7 +214,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
214214
.predicates
215215
.to_errors(CodeAmbiguity)
216216
.into_iter()
217-
.map(|e| to_fulfillment_error(e))
217+
.map(to_fulfillment_error)
218218
.collect();
219219
if errors.is_empty() { Ok(()) } else { Err(errors) }
220220
}

src/librustc_trait_selection/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn astconv_object_safety_violations(
3939
let violations = traits::supertrait_def_ids(tcx, trait_def_id)
4040
.map(|def_id| predicates_reference_self(tcx, def_id, true))
4141
.filter(|spans| !spans.is_empty())
42-
.map(|spans| ObjectSafetyViolation::SupertraitSelf(spans))
42+
.map(ObjectSafetyViolation::SupertraitSelf)
4343
.collect();
4444

4545
debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", trait_def_id, violations);

src/librustc_trait_selection/traits/select.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2947,13 +2947,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
29472947
let existential_predicates = data_a.map_bound(|data_a| {
29482948
let iter = data_a
29492949
.principal()
2950-
.map(|x| ty::ExistentialPredicate::Trait(x))
2950+
.map(ty::ExistentialPredicate::Trait)
29512951
.into_iter()
2952-
.chain(
2953-
data_a
2954-
.projection_bounds()
2955-
.map(|x| ty::ExistentialPredicate::Projection(x)),
2956-
)
2952+
.chain(data_a.projection_bounds().map(ty::ExistentialPredicate::Projection))
29572953
.chain(data_b.auto_traits().map(ty::ExistentialPredicate::AutoTrait));
29582954
tcx.mk_existential_predicates(iter)
29592955
});

src/librustc_typeck/astconv.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1698,9 +1698,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16981698
};
16991699

17001700
// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
1701-
let existential_trait_refs = regular_traits
1702-
.iter()
1703-
.map(|i| i.trait_ref().map_bound(|trait_ref| trait_ref_to_existential(trait_ref)));
1701+
let existential_trait_refs =
1702+
regular_traits.iter().map(|i| i.trait_ref().map_bound(trait_ref_to_existential));
17041703
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
17051704
bound.map_bound(|b| {
17061705
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx));

src/librustc_typeck/check/compare_method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ fn compare_number_of_generics<'tcx>(
677677
impl_count,
678678
kind,
679679
pluralize!(impl_count),
680-
suffix.unwrap_or_else(|| String::new()),
680+
suffix.unwrap_or_else(String::new),
681681
),
682682
);
683683
}

0 commit comments

Comments
 (0)