Skip to content

Commit c9a02c2

Browse files
committed
use .copied() instead of .map(|x| *x) on iterators
1 parent 3f9bddc commit c9a02c2

File tree

16 files changed

+26
-27
lines changed

16 files changed

+26
-27
lines changed

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::cmp::Ord;
2020

2121
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
2222
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
23-
ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect()
23+
ich::IGNORED_ATTRIBUTES.iter().copied().collect()
2424
}
2525

2626
/// This is the context state available during incr. comp. hashing. It contains

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'tcx> ScopeTree {
635635
/// Used to sanity check visit_expr call count when
636636
/// calculating generator interiors.
637637
pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option<usize> {
638-
self.body_expr_count.get(&body_id).map(|r| *r)
638+
self.body_expr_count.get(&body_id).copied()
639639
}
640640
}
641641

src/librustc_ast_lowering/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11791179
let from_err_expr =
11801180
self.wrap_in_try_constructor(sym::from_error, unstable_span, from_expr, try_span);
11811181
let thin_attrs = ThinVec::from(attrs);
1182-
let catch_scope = self.catch_scopes.last().map(|x| *x);
1182+
let catch_scope = self.catch_scopes.last().copied();
11831183
let ret_expr = if let Some(catch_node) = catch_scope {
11841184
let target_id = Ok(self.lower_node_id(catch_node));
11851185
self.arena.alloc(self.expr(

src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'a, 'b> Context<'a, 'b> {
359359
refs.sort();
360360
refs.dedup();
361361
let (arg_list, mut sp) = if refs.len() == 1 {
362-
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.map(|sp| *sp)).collect();
362+
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.copied()).collect();
363363
(
364364
format!("argument {}", refs[0]),
365365
if spans.is_empty() {

src/librustc_expand/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ fn check_matcher_core(
970970
msg,
971971
ts[..ts.len() - 1]
972972
.iter()
973-
.map(|s| *s)
973+
.copied()
974974
.collect::<Vec<_>>()
975975
.join(", "),
976976
ts[ts.len() - 1],

src/librustc_metadata/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tcx> EncodeContext<'tcx> {
503503
},
504504
proc_macro_data,
505505
proc_macro_stability: if is_proc_macro {
506-
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| *stab)
506+
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied()
507507
} else {
508508
None
509509
},

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
305305
let mut caller_iter = caller_args
306306
.iter()
307307
.filter(|op| !rust_abi || !op.layout.is_zst())
308-
.map(|op| *op);
308+
.copied();
309309

310310
// Now we have to spread them out across the callee's locals,
311311
// taking into account the `spread_arg`. If we could write

src/librustc_mir_build/hair/cx/expr.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,12 @@ fn make_mirror_unadjusted<'a, 'tcx>(
187187
if let Some((adt_def, index)) = adt_data {
188188
let substs = cx.tables().node_substs(fun.hir_id);
189189
let user_provided_types = cx.tables().user_provided_types();
190-
let user_ty =
191-
user_provided_types.get(fun.hir_id).map(|u_ty| *u_ty).map(|mut u_ty| {
192-
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
193-
*did = adt_def.did;
194-
}
195-
u_ty
196-
});
190+
let user_ty = user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
191+
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
192+
*did = adt_def.did;
193+
}
194+
u_ty
195+
});
197196
debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
198197

199198
let field_refs = args
@@ -329,7 +328,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
329328
ty::Adt(adt, substs) => match adt.adt_kind() {
330329
AdtKind::Struct | AdtKind::Union => {
331330
let user_provided_types = cx.tables().user_provided_types();
332-
let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
331+
let user_ty = user_provided_types.get(expr.hir_id).copied();
333332
debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
334333
ExprKind::Adt {
335334
adt_def: adt,
@@ -351,7 +350,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
351350

352351
let index = adt.variant_index_with_id(variant_id);
353352
let user_provided_types = cx.tables().user_provided_types();
354-
let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
353+
let user_ty = user_provided_types.get(expr.hir_id).copied();
355354
debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
356355
ExprKind::Adt {
357356
adt_def: adt,
@@ -570,7 +569,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
570569
}
571570
hir::ExprKind::Type(ref source, ref ty) => {
572571
let user_provided_types = cx.tables.user_provided_types();
573-
let user_ty = user_provided_types.get(ty.hir_id).map(|u_ty| *u_ty);
572+
let user_ty = user_provided_types.get(ty.hir_id).copied();
574573
debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
575574
if source.is_syntactic_place_expr() {
576575
ExprKind::PlaceTypeAscription { source: source.to_ref(), user_ty }
@@ -605,7 +604,7 @@ fn user_substs_applied_to_res<'tcx>(
605604
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
606605
| Res::Def(DefKind::Const, _)
607606
| Res::Def(DefKind::AssocConst, _) => {
608-
cx.tables().user_provided_types().get(hir_id).map(|u_ty| *u_ty)
607+
cx.tables().user_provided_types().get(hir_id).copied()
609608
}
610609

611610
// A unit struct/variant which is used as a value (e.g.,
@@ -744,7 +743,7 @@ fn convert_path_expr<'a, 'tcx>(
744743

745744
Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
746745
let user_provided_types = cx.tables.user_provided_types();
747-
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
746+
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
748747
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
749748
let ty = cx.tables().node_type(expr.hir_id);
750749
match ty.kind {

src/librustc_mir_build/hair/pattern/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
411411
}
412412

413413
fn iter(&self) -> impl Iterator<Item = &Pat<'tcx>> {
414-
self.0.iter().map(|p| *p)
414+
self.0.iter().copied()
415415
}
416416

417417
// If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`.

src/librustc_span/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl SourceMap {
206206
&self,
207207
stable_id: StableSourceFileId,
208208
) -> Option<Lrc<SourceFile>> {
209-
self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|sf| sf.clone())
209+
self.files.borrow().stable_id_to_source_file.get(&stable_id).cloned()
210210
}
211211

212212
fn allocate_address_space(&self, size: usize) -> Result<usize, OffsetOverflowError> {

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
167167
.skip_binder()
168168
.get(0)
169169
.filter(|ty| ty.is_region_ptr() && !rcvr_ty.is_region_ptr())
170-
.map(|ty| *ty)
170+
.copied()
171171
.unwrap_or(rcvr_ty),
172172
};
173173
print_disambiguation_help(

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ fn check_fn<'a, 'tcx>(
13151315
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
13161316

13171317
// Resume type defaults to `()` if the generator has no argument.
1318-
let resume_ty = fn_sig.inputs().get(0).map(|ty| *ty).unwrap_or_else(|| tcx.mk_unit());
1318+
let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| tcx.mk_unit());
13191319

13201320
fcx.resume_yield_tys = Some((resume_ty, yield_ty));
13211321
}

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ fn from_target_feature(
22362236
};
22372237

22382238
// Only allow features whose feature gates have been enabled.
2239-
let allowed = match feature_gate.as_ref().map(|s| *s) {
2239+
let allowed = match feature_gate.as_ref().copied() {
22402240
Some(sym::arm_target_feature) => rust_features.arm_target_feature,
22412241
Some(sym::aarch64_target_feature) => rust_features.aarch64_target_feature,
22422242
Some(sym::hexagon_target_feature) => rust_features.hexagon_target_feature,

src/librustc_typeck/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
2525
hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => {
2626
let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE);
2727

28-
let predicates = crate_map.predicates.get(&item_def_id).map(|p| *p).unwrap_or(&[]);
28+
let predicates = crate_map.predicates.get(&item_def_id).copied().unwrap_or(&[]);
2929

3030
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
3131
let mut pred: Vec<String> = predicates

src/librustc_typeck/variance/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
7979
// Everything else must be inferred.
8080

8181
let crate_map = tcx.crate_variances(LOCAL_CRATE);
82-
crate_map.variances.get(&item_def_id).map(|p| *p).unwrap_or(&[])
82+
crate_map.variances.get(&item_def_id).copied().unwrap_or(&[])
8383
}

src/libtest/test_result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn calc_result<'a>(
4040
let maybe_panic_str = err
4141
.downcast_ref::<String>()
4242
.map(|e| &**e)
43-
.or_else(|| err.downcast_ref::<&'static str>().map(|e| *e));
43+
.or_else(|| err.downcast_ref::<&'static str>().copied());
4444

4545
if maybe_panic_str.map(|e| e.contains(msg)).unwrap_or(false) {
4646
TestResult::TrOk

0 commit comments

Comments
 (0)