Skip to content
/ rust Public
forked from rust-lang/rust

Commit aa2289d

Browse files
authored
Rollup merge of rust-lang#117549 - DaniPopes:more-copied, r=b-naber
Use `copied` instead of manual `map`
2 parents ca3a028 + 2736430 commit aa2289d

File tree

8 files changed

+10
-11
lines changed

8 files changed

+10
-11
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4242
}
4343
// Merge attributes into the inner expression.
4444
if !e.attrs.is_empty() {
45-
let old_attrs =
46-
self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]);
45+
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
4746
self.attrs.insert(
4847
ex.hir_id.local_id,
4948
&*self.arena.alloc_from_iter(

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
499499
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
500500
/// resolver (if any).
501501
fn orig_opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
502-
self.resolver.node_id_to_def_id.get(&node).map(|local_def_id| *local_def_id)
502+
self.resolver.node_id_to_def_id.get(&node).copied()
503503
}
504504

505505
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
@@ -542,7 +542,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
542542
self.generics_def_id_map
543543
.iter()
544544
.rev()
545-
.find_map(|map| map.get(&local_def_id).map(|local_def_id| *local_def_id))
545+
.find_map(|map| map.get(&local_def_id).copied())
546546
.unwrap_or(local_def_id)
547547
}
548548

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
860860
self.suggest_boxing_for_return_impl_trait(
861861
err,
862862
ret_sp,
863-
prior_arms.iter().chain(std::iter::once(&arm_span)).map(|s| *s),
863+
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
864864
);
865865
}
866866
}

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ pub trait LintContext {
703703
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
704704
},
705705
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
706-
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().map(|s| *s).collect();
706+
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().copied().collect();
707707

708708
// Suggest the most probable if we found one
709709
if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ pub fn write_allocations<'tcx>(
13371337
fn alloc_ids_from_alloc(
13381338
alloc: ConstAllocation<'_>,
13391339
) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
1340-
alloc.inner().provenance().ptrs().values().map(|id| *id)
1340+
alloc.inner().provenance().ptrs().values().copied()
13411341
}
13421342

13431343
fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {

compiler/rustc_ty_utils/src/assoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
4343
trait_fn_def_id,
4444
)
4545
})
46-
.map(|def_id| *def_id),
46+
.copied(),
4747
),
4848
)
4949
}
@@ -69,7 +69,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
6969
impl_fn_def_id,
7070
)
7171
})
72-
.map(|def_id| *def_id)
72+
.copied()
7373
})),
7474
)
7575
}

library/core/src/array/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ where
206206

207207
#[inline]
208208
fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> {
209-
<&Self>::try_from(slice).map(|r| *r)
209+
<&Self>::try_from(slice).copied()
210210
}
211211
}
212212

library/core/src/iter/adapters/copied.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ where
193193
T: Copy,
194194
{
195195
default fn spec_next_chunk(&mut self) -> Result<[T; N], array::IntoIter<T, N>> {
196-
array::iter_next_chunk(&mut self.map(|e| *e))
196+
array::iter_next_chunk(&mut self.copied())
197197
}
198198
}
199199

0 commit comments

Comments
 (0)