Skip to content

Commit

Permalink
Rollup merge of rust-lang#70269 - matthiaskrgr:clippy_closures, r=Dyl…
Browse files Browse the repository at this point in the history
…an-DPC

remove redundant closures (clippy::redundant_closure)
  • Loading branch information
Centril authored Mar 23, 2020
2 parents b7f28fb + 263cbd1 commit 353e4a0
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
(root, length)
};

out_node.push(k, v, subroot.unwrap_or_else(|| node::Root::new_leaf()));
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
out_tree.length += 1 + sublength;
}
}
Expand Down Expand Up @@ -2147,7 +2147,7 @@ impl<K, V> BTreeMap<K, V> {
/// If the root node is the empty (non-allocated) root node, allocate our
/// own node.
fn ensure_root_is_owned(&mut self) -> &mut node::Root<K, V> {
self.root.get_or_insert_with(|| node::Root::new_leaf())
self.root.get_or_insert_with(node::Root::new_leaf)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl DepGraph {
C: DepGraphSafe + StableHashingContextProvider<'a>,
{
if let Some(ref data) = self.data {
let task_deps = create_task(key).map(|deps| Lock::new(deps));
let task_deps = create_task(key).map(Lock::new);

// In incremental mode, hash the result of the task. We don't
// do anything with the hash yet, but we are computing it
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl UndefMask {
}

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

match idx {
Some(idx) => Err(idx),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl ParenthesizedArgs {
pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
AngleBracketedArgs {
span: self.span,
args: self.inputs.iter().cloned().map(|input| GenericArg::Type(input)).collect(),
args: self.inputs.iter().cloned().map(GenericArg::Type).collect(),
constraints: vec![],
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if !generic_args.parenthesized && !has_lifetimes {
generic_args.args = self
.elided_path_lifetimes(path_span, expected_lifetimes)
.map(|lt| GenericArg::Lifetime(lt))
.map(GenericArg::Lifetime)
.chain(generic_args.args.into_iter())
.collect();
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl<'a> Path<'a> {
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
let params = lt
.into_iter()
.map(|lt| GenericArg::Lifetime(lt))
.chain(tys.into_iter().map(|ty| GenericArg::Type(ty)))
.map(GenericArg::Lifetime)
.chain(tys.into_iter().map(GenericArg::Type))
.collect();

match self.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Sharded<T> {
impl<T: Default> Default for Sharded<T> {
#[inline]
fn default() -> Self {
Self::new(|| T::default())
Self::new(T::default)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'a> DiagnosticBuilder<'a> {
message: &str,
span: Option<S>,
) -> &mut Self {
let span = span.map(|s| s.into()).unwrap_or_else(|| MultiSpan::new());
let span = span.map(|s| s.into()).unwrap_or_else(MultiSpan::new);
self.0.diagnostic.sub(level, message, span, None);
self
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_feature/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct Feature {

impl Feature {
fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(|i| NonZeroU32::new(i))
self.issue.and_then(NonZeroU32::new)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl<'tcx> QueryContext<'tcx> {
where
F: FnOnce(TyCtxt<'tcx>) -> R,
{
ty::tls::enter_global(self.0, |tcx| f(tcx))
ty::tls::enter_global(self.0, f)
}

pub fn print_stats(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'a> CrateLocator<'a> {
.into_iter()
.filter_map(|entry| entry.files())
.flatten()
.map(|location| PathBuf::from(location))
.map(PathBuf::from)
.collect()
} else {
// SVH being specified means this is a transitive dependency,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/generic/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ fn write_diff<A: Analysis<'tcx>>(
let mut clear = HybridBitSet::new_empty(len);

// FIXME: Implement a lazy iterator over the symmetric difference of two bitsets.
for i in (0..len).map(|i| A::Idx::new(i)) {
for i in (0..len).map(A::Idx::new) {
match (from.contains(i), to.contains(i)) {
(false, true) => set.insert(i),
(true, false) => clear.insert(i),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
.unwrap()
})
.filter(|&instance| should_monomorphize_locally(tcx, &instance))
.map(|instance| create_fn_mono_item(instance));
.map(create_fn_mono_item);
output.extend(methods);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ fn split_grouped_constructors<'p, 'tcx>(
}
intersection
})
.flat_map(|range| range_borders(range));
.flat_map(range_borders);
let ctor_borders = range_borders(ctor_range.clone());
let mut borders: Vec<_> = row_borders.chain(ctor_borders).collect();
borders.sort_unstable();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {

let sub_span = path.segments.last().unwrap().ident.span;
if !self.span.filter_generated(sub_span) {
let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id));
let ref_id = self.lookup_def_id(id).map(id_from_def_id);
let alias_span = alias.map(|i| self.span_from_span(i.span));
let span = self.span_from_span(sub_span);
self.dumper.import(
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
.as_ref()
.and_then(|t| self.lookup_def_id(t.ref_id))
.map(id_from_def_id)
.unwrap_or_else(|| null_id()),
.unwrap_or_else(null_id),
},
Impl {
id: impl_id,
Expand Down Expand Up @@ -487,9 +487,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
qualname,
// FIXME you get better data here by using the visitor.
value: String::new(),
parent: parent_scope.map(|id| id_from_def_id(id)),
parent: parent_scope.map(id_from_def_id),
children: vec![],
decl_id: decl_id.map(|id| id_from_def_id(id)),
decl_id: decl_id.map(id_from_def_id),
docs,
sig: None,
attributes: lower_attributes(attributes, self),
Expand Down Expand Up @@ -541,7 +541,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
.tcx
.find_field_index(ident, variant)
.map(|index| id_from_def_id(variant.fields[index].did))
.unwrap_or_else(|| null_id()),
.unwrap_or_else(null_id),
}))
}
ty::Tuple(..) => None,
Expand Down Expand Up @@ -590,14 +590,11 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
Some(Data::RefData(Ref {
kind: RefKind::Function,
span,
ref_id: def_id
.or(decl_id)
.map(|id| id_from_def_id(id))
.unwrap_or_else(|| null_id()),
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(|| null_id()),
}))
}
ast::ExprKind::Path(_, ref path) => {
self.get_path_data(expr.id, path).map(|d| Data::RefData(d))
self.get_path_data(expr.id, path).map(Data::RefData)
}
_ => {
// FIXME
Expand Down Expand Up @@ -1075,7 +1072,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {

fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
let def_id = scx.tcx.hir().opt_local_def_id_from_node_id(id);
def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| {
def_id.map(id_from_def_id).unwrap_or_else(|| {
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
// out of the maximum u32 value. This will work unless you have *billions*
// of definitions in a single crate (very unlikely to actually happen).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ fn select_incremental_path(
(None, Some(path)) => Some(path),
(None, None) => None,
}
.map(|m| PathBuf::from(m))
.map(PathBuf::from)
}

fn collect_print_requests(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trait_selection/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
// FIXME: if we kept the original cache key, we could mark projection
// obligations as complete for the projection cache here.

errors.extend(outcome.errors.into_iter().map(|e| to_fulfillment_error(e)));
errors.extend(outcome.errors.into_iter().map(to_fulfillment_error));

// If nothing new was added, no need to keep looping.
if outcome.stalled {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
.predicates
.to_errors(CodeAmbiguity)
.into_iter()
.map(|e| to_fulfillment_error(e))
.map(to_fulfillment_error)
.collect();
if errors.is_empty() { Ok(()) } else { Err(errors) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn astconv_object_safety_violations(
let violations = traits::supertrait_def_ids(tcx, trait_def_id)
.map(|def_id| predicates_reference_self(tcx, def_id, true))
.filter(|spans| !spans.is_empty())
.map(|spans| ObjectSafetyViolation::SupertraitSelf(spans))
.map(ObjectSafetyViolation::SupertraitSelf)
.collect();

debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", trait_def_id, violations);
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_trait_selection/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2947,13 +2947,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let existential_predicates = data_a.map_bound(|data_a| {
let iter = data_a
.principal()
.map(|x| ty::ExistentialPredicate::Trait(x))
.map(ty::ExistentialPredicate::Trait)
.into_iter()
.chain(
data_a
.projection_bounds()
.map(|x| ty::ExistentialPredicate::Projection(x)),
)
.chain(data_a.projection_bounds().map(ty::ExistentialPredicate::Projection))
.chain(data_b.auto_traits().map(ty::ExistentialPredicate::AutoTrait));
tcx.mk_existential_predicates(iter)
});
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,9 +1693,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};

// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
let existential_trait_refs = regular_traits
.iter()
.map(|i| i.trait_ref().map_bound(|trait_ref| trait_ref_to_existential(trait_ref)));
let existential_trait_refs =
regular_traits.iter().map(|i| i.trait_ref().map_bound(trait_ref_to_existential));
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
bound.map_bound(|b| {
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ fn compare_number_of_generics<'tcx>(
impl_count,
kind,
pluralize!(impl_count),
suffix.unwrap_or_else(|| String::new()),
suffix.unwrap_or_else(String::new),
),
);
}
Expand Down

0 comments on commit 353e4a0

Please sign in to comment.