Rollup merge of #117549 - DaniPopes:more-copied, r=b-naber

Use `copied` instead of manual `map`
This commit is contained in:
Matthias Krüger 2023-11-17 23:04:22 +01:00 committed by GitHub
commit aa2289d3bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 11 deletions

View File

@ -42,8 +42,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
}
// Merge attributes into the inner expression.
if !e.attrs.is_empty() {
let old_attrs =
self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]);
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
self.attrs.insert(
ex.hir_id.local_id,
&*self.arena.alloc_from_iter(

View File

@ -499,7 +499,7 @@ fn next_node_id(&mut self) -> NodeId {
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
/// resolver (if any).
fn orig_opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
self.resolver.node_id_to_def_id.get(&node).map(|local_def_id| *local_def_id)
self.resolver.node_id_to_def_id.get(&node).copied()
}
/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
@ -542,7 +542,7 @@ fn get_remapped_def_id(&self, local_def_id: LocalDefId) -> LocalDefId {
self.generics_def_id_map
.iter()
.rev()
.find_map(|map| map.get(&local_def_id).map(|local_def_id| *local_def_id))
.find_map(|map| map.get(&local_def_id).copied())
.unwrap_or(local_def_id)
}

View File

@ -860,7 +860,7 @@ fn note_error_origin(
self.suggest_boxing_for_return_impl_trait(
err,
ret_sp,
prior_arms.iter().chain(std::iter::once(&arm_span)).map(|s| *s),
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
);
}
}

View File

@ -703,7 +703,7 @@ fn lookup_with_diagnostics(
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");
},
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().map(|s| *s).collect();
let possibilities: Vec<Symbol> = sess.parse_sess.check_config.expecteds.keys().copied().collect();
// Suggest the most probable if we found one
if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {

View File

@ -1337,7 +1337,7 @@ pub fn write_allocations<'tcx>(
fn alloc_ids_from_alloc(
alloc: ConstAllocation<'_>,
) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
alloc.inner().provenance().ptrs().values().map(|id| *id)
alloc.inner().provenance().ptrs().values().copied()
}
fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {

View File

@ -43,7 +43,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
trait_fn_def_id,
)
})
.map(|def_id| *def_id),
.copied(),
),
)
}
@ -69,7 +69,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] {
impl_fn_def_id,
)
})
.map(|def_id| *def_id)
.copied()
})),
)
}

View File

@ -206,7 +206,7 @@ fn borrow_mut(&mut self) -> &mut [T] {
#[inline]
fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> {
<&Self>::try_from(slice).map(|r| *r)
<&Self>::try_from(slice).copied()
}
}

View File

@ -193,7 +193,7 @@ impl<'a, const N: usize, I, T: 'a> SpecNextChunk<'a, N, T> for I
T: Copy,
{
default fn spec_next_chunk(&mut self) -> Result<[T; N], array::IntoIter<T, N>> {
array::iter_next_chunk(&mut self.map(|e| *e))
array::iter_next_chunk(&mut self.copied())
}
}