diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 2cb8388aca63f..d8be4194c9e16 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -20,7 +20,7 @@ use std::cmp::Ord; fn compute_ignored_attr_names() -> FxHashSet { debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty()); - ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect() + ich::IGNORED_ATTRIBUTES.iter().copied().collect() } /// This is the context state available during incr. comp. hashing. It contains diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 9e9c8bd846473..1d043f5dcdefa 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -635,7 +635,7 @@ impl<'tcx> ScopeTree { /// Used to sanity check visit_expr call count when /// calculating generator interiors. pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option { - self.body_expr_count.get(&body_id).map(|r| *r) + self.body_expr_count.get(&body_id).copied() } } diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs index d781fbde59cb7..23ec924573cdc 100644 --- a/src/librustc_ast_lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -1179,7 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let from_err_expr = self.wrap_in_try_constructor(sym::from_error, unstable_span, from_expr, try_span); let thin_attrs = ThinVec::from(attrs); - let catch_scope = self.catch_scopes.last().map(|x| *x); + let catch_scope = self.catch_scopes.last().copied(); let ret_expr = if let Some(catch_node) = catch_scope { let target_id = Ok(self.lower_node_id(catch_node)); self.arena.alloc(self.expr( diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 0684662b2bfe1..9092caef60a93 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -359,7 +359,7 @@ impl<'a, 'b> Context<'a, 'b> { refs.sort(); refs.dedup(); let (arg_list, mut sp) = if refs.len() == 1 { - let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.map(|sp| *sp)).collect(); + let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.copied()).collect(); ( format!("argument {}", refs[0]), if spans.is_empty() { diff --git a/src/librustc_expand/mbe/macro_rules.rs b/src/librustc_expand/mbe/macro_rules.rs index 52e581e30f537..3607e59a52cb4 100644 --- a/src/librustc_expand/mbe/macro_rules.rs +++ b/src/librustc_expand/mbe/macro_rules.rs @@ -970,7 +970,7 @@ fn check_matcher_core( msg, ts[..ts.len() - 1] .iter() - .map(|s| *s) + .copied() .collect::>() .join(", "), ts[ts.len() - 1], diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index ee54f40ece5c8..79dc4364a6164 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -503,7 +503,7 @@ impl<'tcx> EncodeContext<'tcx> { }, proc_macro_data, proc_macro_stability: if is_proc_macro { - tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| *stab) + tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied() } else { None }, diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index a02a6898c1d71..53e10f86a2cec 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let mut caller_iter = caller_args .iter() .filter(|op| !rust_abi || !op.layout.is_zst()) - .map(|op| *op); + .copied(); // Now we have to spread them out across the callee's locals, // taking into account the `spread_arg`. If we could write diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 74006c883716c..46d49b6b4933f 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -187,13 +187,12 @@ fn make_mirror_unadjusted<'a, 'tcx>( if let Some((adt_def, index)) = adt_data { let substs = cx.tables().node_substs(fun.hir_id); let user_provided_types = cx.tables().user_provided_types(); - let user_ty = - user_provided_types.get(fun.hir_id).map(|u_ty| *u_ty).map(|mut u_ty| { - if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value { - *did = adt_def.did; - } - u_ty - }); + let user_ty = user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| { + if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value { + *did = adt_def.did; + } + u_ty + }); debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty); let field_refs = args @@ -329,7 +328,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( ty::Adt(adt, substs) => match adt.adt_kind() { AdtKind::Struct | AdtKind::Union => { let user_provided_types = cx.tables().user_provided_types(); - let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty); + let user_ty = user_provided_types.get(expr.hir_id).copied(); debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty); ExprKind::Adt { adt_def: adt, @@ -351,7 +350,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( let index = adt.variant_index_with_id(variant_id); let user_provided_types = cx.tables().user_provided_types(); - let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty); + let user_ty = user_provided_types.get(expr.hir_id).copied(); debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty); ExprKind::Adt { adt_def: adt, @@ -570,7 +569,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( } hir::ExprKind::Type(ref source, ref ty) => { let user_provided_types = cx.tables.user_provided_types(); - let user_ty = user_provided_types.get(ty.hir_id).map(|u_ty| *u_ty); + let user_ty = user_provided_types.get(ty.hir_id).copied(); debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty); if source.is_syntactic_place_expr() { ExprKind::PlaceTypeAscription { source: source.to_ref(), user_ty } @@ -605,7 +604,7 @@ fn user_substs_applied_to_res<'tcx>( | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => { - cx.tables().user_provided_types().get(hir_id).map(|u_ty| *u_ty) + cx.tables().user_provided_types().get(hir_id).copied() } // A unit struct/variant which is used as a value (e.g., @@ -744,7 +743,7 @@ fn convert_path_expr<'a, 'tcx>( Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => { let user_provided_types = cx.tables.user_provided_types(); - let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty); + let user_provided_type = user_provided_types.get(expr.hir_id).copied(); debug!("convert_path_expr: user_provided_type={:?}", user_provided_type); let ty = cx.tables().node_type(expr.hir_id); match ty.kind { diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 85f03629b646a..90e4f53647846 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -411,7 +411,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> { } fn iter(&self) -> impl Iterator> { - self.0.iter().map(|p| *p) + self.0.iter().copied() } // If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`. diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs index 31d397f040cb0..3b665e1d6dc05 100644 --- a/src/librustc_span/source_map.rs +++ b/src/librustc_span/source_map.rs @@ -206,7 +206,7 @@ impl SourceMap { &self, stable_id: StableSourceFileId, ) -> Option> { - self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone()) + self.files.borrow().stable_id_to_source_file.get(&stable_id).cloned() } fn allocate_address_space(&self, size: usize) -> Result { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 44f87319ebf4f..97ed50b3500c0 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .skip_binder() .get(0) .filter(|ty| ty.is_region_ptr() && !rcvr_ty.is_region_ptr()) - .map(|ty| *ty) + .copied() .unwrap_or(rcvr_ty), }; print_disambiguation_help( diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ce2af9b96e57c..d025f81153f70 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1315,7 +1315,7 @@ fn check_fn<'a, 'tcx>( fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType); // Resume type defaults to `()` if the generator has no argument. - let resume_ty = fn_sig.inputs().get(0).map(|ty| *ty).unwrap_or_else(|| tcx.mk_unit()); + let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| tcx.mk_unit()); fcx.resume_yield_tys = Some((resume_ty, yield_ty)); } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 252abaee747f5..7ec3686c013d5 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2236,7 +2236,7 @@ fn from_target_feature( }; // Only allow features whose feature gates have been enabled. - let allowed = match feature_gate.as_ref().map(|s| *s) { + let allowed = match feature_gate.as_ref().copied() { Some(sym::arm_target_feature) => rust_features.arm_target_feature, Some(sym::aarch64_target_feature) => rust_features.aarch64_target_feature, Some(sym::hexagon_target_feature) => rust_features.hexagon_target_feature, diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 519873910976b..f7b6e0fce5a21 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -25,7 +25,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => { let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE); - let predicates = crate_map.predicates.get(&item_def_id).map(|p| *p).unwrap_or(&[]); + let predicates = crate_map.predicates.get(&item_def_id).copied().unwrap_or(&[]); if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec = predicates diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index 32bd7e4c4c1d0..ddde11b38448b 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -79,5 +79,5 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] { // Everything else must be inferred. let crate_map = tcx.crate_variances(LOCAL_CRATE); - crate_map.variances.get(&item_def_id).map(|p| *p).unwrap_or(&[]) + crate_map.variances.get(&item_def_id).copied().unwrap_or(&[]) } diff --git a/src/libtest/test_result.rs b/src/libtest/test_result.rs index bfa572c887a52..5c975c6272b97 100644 --- a/src/libtest/test_result.rs +++ b/src/libtest/test_result.rs @@ -40,7 +40,7 @@ pub fn calc_result<'a>( let maybe_panic_str = err .downcast_ref::() .map(|e| &**e) - .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)); + .or_else(|| err.downcast_ref::<&'static str>().copied()); if maybe_panic_str.map(|e| e.contains(msg)).unwrap_or(false) { TestResult::TrOk