diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 3ba7befc04609..bde66c406af7f 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -196,7 +196,7 @@ impl Clone for BTreeMap { (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; } } @@ -2147,7 +2147,7 @@ impl BTreeMap { /// 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 { - self.root.get_or_insert_with(|| node::Root::new_leaf()) + self.root.get_or_insert_with(node::Root::new_leaf) } } diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 40192d072eb0f..f3ae2b3d57a8f 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -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 diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 9474f05b55df7..dd2a3f6c29a76 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -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), diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index b7b50617eaaf8..9d00cbe1951ea 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -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![], } } diff --git a/src/librustc_ast_lowering/path.rs b/src/librustc_ast_lowering/path.rs index b5b0a3089ce0f..91b61ebbce69a 100644 --- a/src/librustc_ast_lowering/path.rs +++ b/src/librustc_ast_lowering/path.rs @@ -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 { diff --git a/src/librustc_builtin_macros/deriving/generic/ty.rs b/src/librustc_builtin_macros/deriving/generic/ty.rs index bd54a73531197..d83c98572a272 100644 --- a/src/librustc_builtin_macros/deriving/generic/ty.rs +++ b/src/librustc_builtin_macros/deriving/generic/ty.rs @@ -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 { diff --git a/src/librustc_data_structures/sharded.rs b/src/librustc_data_structures/sharded.rs index d08d46a7414d0..485719c517564 100644 --- a/src/librustc_data_structures/sharded.rs +++ b/src/librustc_data_structures/sharded.rs @@ -30,7 +30,7 @@ pub struct Sharded { impl Default for Sharded { #[inline] fn default() -> Self { - Self::new(|| T::default()) + Self::new(T::default) } } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 008d2e92418f9..fffae0bfd24d9 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -162,7 +162,7 @@ impl<'a> DiagnosticBuilder<'a> { message: &str, span: Option, ) -> &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 } diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index 01546f7825774..f8bf0315d0c9f 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -51,7 +51,7 @@ pub struct Feature { impl Feature { fn issue(&self) -> Option { - self.issue.and_then(|i| NonZeroU32::new(i)) + self.issue.and_then(NonZeroU32::new) } } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 8d9e287cdc9d6..cb1ed87b02fda 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -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) { diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 2f9be599ba94b..c1a95c094b10c 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -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, diff --git a/src/librustc_mir/dataflow/generic/graphviz.rs b/src/librustc_mir/dataflow/generic/graphviz.rs index 36decf7f5a9c3..c15f2a726ee70 100644 --- a/src/librustc_mir/dataflow/generic/graphviz.rs +++ b/src/librustc_mir/dataflow/generic/graphviz.rs @@ -577,7 +577,7 @@ fn write_diff>( 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), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index a592e8d9c05fe..cbd19f080eb9e 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -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); } diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 82810f356759d..89063a4227fa9 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -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(); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 8d1a39eab89d8..a80c3b72044ef 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -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( diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index bb717981a3be7..024633c3b3dec 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -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, @@ -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), @@ -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, @@ -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 @@ -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). diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index f16e4ca93d80a..6c4d70c09a39a 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -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( diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 5def77ce7324c..260363a5d1fb5 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -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 { @@ -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) } } diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 452f965014bff..5cc1da045fc37 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -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); diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 660d4d14bc728..2f59620be93c3 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -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) }); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 3ee6d5df7356b..408e5c2d2f24d 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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)); diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 6178158e4e504..f666ef72d5278 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -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), ), ); }