use .copied() instead of .map(|x| *x) on iterators
This commit is contained in:
parent
3f9bddc7fe
commit
c9a02c2e42
16 changed files with 26 additions and 27 deletions
|
|
@ -20,7 +20,7 @@ use std::cmp::Ord;
|
|||
|
||||
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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<usize> {
|
||||
self.body_expr_count.get(&body_id).map(|r| *r)
|
||||
self.body_expr_count.get(&body_id).copied()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -970,7 +970,7 @@ fn check_matcher_core(
|
|||
msg,
|
||||
ts[..ts.len() - 1]
|
||||
.iter()
|
||||
.map(|s| *s)
|
||||
.copied()
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
ts[ts.len() - 1],
|
||||
|
|
|
|||
|
|
@ -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
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
|
|||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &Pat<'tcx>> {
|
||||
self.0.iter().map(|p| *p)
|
||||
self.0.iter().copied()
|
||||
}
|
||||
|
||||
// If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`.
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ impl SourceMap {
|
|||
&self,
|
||||
stable_id: StableSourceFileId,
|
||||
) -> Option<Lrc<SourceFile>> {
|
||||
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<usize, OffsetOverflowError> {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<String> = predicates
|
||||
|
|
|
|||
|
|
@ -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(&[])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ pub fn calc_result<'a>(
|
|||
let maybe_panic_str = err
|
||||
.downcast_ref::<String>()
|
||||
.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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue