diff --git a/src/librustc_codegen_ssa/debuginfo/type_names.rs b/src/librustc_codegen_ssa/debuginfo/type_names.rs index 1d8730db546..57a3d8b5edc 100644 --- a/src/librustc_codegen_ssa/debuginfo/type_names.rs +++ b/src/librustc_codegen_ssa/debuginfo/type_names.rs @@ -48,7 +48,7 @@ pub fn push_debuginfo_type_name<'tcx>( } ty::Tuple(component_types) => { output.push('('); - for &component_type in component_types { + for component_type in component_types { push_debuginfo_type_name(tcx, component_type.expect_ty(), true, output, visited); output.push_str(", "); } diff --git a/src/librustc_infer/infer/canonical/mod.rs b/src/librustc_infer/infer/canonical/mod.rs index 7f58b29a73f..7310d2c3bdc 100644 --- a/src/librustc_infer/infer/canonical/mod.rs +++ b/src/librustc_infer/infer/canonical/mod.rs @@ -87,7 +87,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { ) -> CanonicalVarValues<'tcx> { let var_values: IndexVec> = variables .iter() - .map(|info| self.instantiate_canonical_var(span, *info, &universe_map)) + .map(|info| self.instantiate_canonical_var(span, info, &universe_map)) .collect(); CanonicalVarValues { var_values } diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index 23c9eeb21bb..ab2393918c3 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -464,12 +464,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { if info.is_existential() { match opt_values[BoundVar::new(index)] { Some(k) => k, - None => self.instantiate_canonical_var(cause.span, *info, |u| { + None => self.instantiate_canonical_var(cause.span, info, |u| { universe_map[u.as_usize()] }), } } else { - self.instantiate_canonical_var(cause.span, *info, |u| { + self.instantiate_canonical_var(cause.span, info, |u| { universe_map[u.as_usize()] }) } diff --git a/src/librustc_infer/infer/outlives/verify.rs b/src/librustc_infer/infer/outlives/verify.rs index cac1d2f050e..82d32b00808 100644 --- a/src/librustc_infer/infer/outlives/verify.rs +++ b/src/librustc_infer/infer/outlives/verify.rs @@ -50,7 +50,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // for further background and discussion. let mut bounds = substs .iter() - .filter_map(|&child| match child.unpack() { + .filter_map(|child| match child.unpack() { GenericArgKind::Type(ty) => Some(self.type_bound(ty)), GenericArgKind::Lifetime(_) => None, GenericArgKind::Const(_) => Some(self.recursive_bound(child)), @@ -223,8 +223,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // like `T` and `T::Item`. It may not work as well for things // like `>::Item`. let c_b = self.param_env.caller_bounds; - let param_bounds = - self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter().copied()); + let param_bounds = self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter()); // Next, collect regions we scraped from the well-formedness // constraints in the fn signature. To do that, we walk the list diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 8247338ae0f..ebdf738b417 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2077,10 +2077,10 @@ impl Debug for Place<'_> { ProjectionElem::ConstantIndex { offset, min_length, from_end: true } => { write!(fmt, "[-{:?} of {:?}]", offset, min_length)?; } - ProjectionElem::Subslice { from, to, from_end: true } if *to == 0 => { + ProjectionElem::Subslice { from, to, from_end: true } if to == 0 => { write!(fmt, "[{:?}:]", from)?; } - ProjectionElem::Subslice { from, to, from_end: true } if *from == 0 => { + ProjectionElem::Subslice { from, to, from_end: true } if from == 0 => { write!(fmt, "[:-{:?}]", to)?; } ProjectionElem::Subslice { from, to, from_end: true } => { diff --git a/src/librustc_middle/ty/flags.rs b/src/librustc_middle/ty/flags.rs index 042ffc4d1e5..edcb69c5e8c 100644 --- a/src/librustc_middle/ty/flags.rs +++ b/src/librustc_middle/ty/flags.rs @@ -129,7 +129,7 @@ impl FlagComputation { &ty::Dynamic(ref obj, r) => { let mut computation = FlagComputation::new(); for predicate in obj.skip_binder().iter() { - match *predicate { + match predicate { ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs), ty::ExistentialPredicate::Projection(p) => { let mut proj_computation = FlagComputation::new(); diff --git a/src/librustc_middle/ty/list.rs b/src/librustc_middle/ty/list.rs index 6427c547a8f..161783bb370 100644 --- a/src/librustc_middle/ty/list.rs +++ b/src/librustc_middle/ty/list.rs @@ -5,6 +5,7 @@ use rustc_serialize::{Encodable, Encoder}; use std::cmp::{self, Ordering}; use std::fmt; use std::hash::{Hash, Hasher}; +use std::iter; use std::mem; use std::ops::Deref; use std::ptr; @@ -21,6 +22,10 @@ extern "C" { /// the same contents can exist in the same context. /// This means we can use pointer for both /// equality comparisons and hashing. +/// +/// Unlike slices, The types contained in `List` are expected to be `Copy` +/// and iterating over a `List` returns `T` instead of a reference. +/// /// Note: `Slice` was already taken by the `Ty`. #[repr(C)] pub struct List { @@ -61,6 +66,15 @@ impl List { result } } + + // If this method didn't exist, we would use `slice.iter` due to + // deref coercion. + // + // This would be weird, as `self.into_iter` iterates over `T` directly. + #[inline(always)] + pub fn iter(&self) -> <&'_ List as IntoIterator>::IntoIter { + self.into_iter() + } } impl fmt::Debug for List { @@ -128,12 +142,12 @@ impl AsRef<[T]> for List { } } -impl<'a, T> IntoIterator for &'a List { - type Item = &'a T; - type IntoIter = <&'a [T] as IntoIterator>::IntoIter; +impl<'a, T: Copy> IntoIterator for &'a List { + type Item = T; + type IntoIter = iter::Copied<<&'a [T] as IntoIterator>::IntoIter>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { - self[..].iter() + self[..].iter().copied() } } diff --git a/src/librustc_middle/ty/outlives.rs b/src/librustc_middle/ty/outlives.rs index 3e6a12df688..1da042e1617 100644 --- a/src/librustc_middle/ty/outlives.rs +++ b/src/librustc_middle/ty/outlives.rs @@ -70,7 +70,7 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo // consistent with previous (accidental) behavior. // See https://github.com/rust-lang/rust/issues/70917 // for further background and discussion. - for &child in substs { + for child in substs { match child.unpack() { GenericArgKind::Type(ty) => { compute_components(tcx, ty, out); diff --git a/src/librustc_middle/ty/print/obsolete.rs b/src/librustc_middle/ty/print/obsolete.rs index 41a6cd5466f..7d9943ab079 100644 --- a/src/librustc_middle/ty/print/obsolete.rs +++ b/src/librustc_middle/ty/print/obsolete.rs @@ -47,7 +47,7 @@ impl DefPathBasedNames<'tcx> { } ty::Tuple(component_types) => { output.push('('); - for &component_type in component_types { + for component_type in component_types { self.push_type_name(component_type.expect_ty(), output, debug); output.push_str(", "); } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index f4b795e5488..e5eb6ce3fb4 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -495,7 +495,7 @@ pub trait PrettyPrinter<'tcx>: } ty::Never => p!(write("!")), ty::Tuple(ref tys) => { - p!(write("("), comma_sep(tys.iter().copied())); + p!(write("("), comma_sep(tys.iter())); if tys.len() == 1 { p!(write(",")); } @@ -560,7 +560,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) print this with `print_def_path`. if !substs.is_empty() { p!(write("::")); - p!(generic_delimiters(|cx| cx.comma_sep(substs.iter().copied()))); + p!(generic_delimiters(|cx| cx.comma_sep(substs.iter()))); } return Ok(self); } @@ -1935,7 +1935,7 @@ define_print_and_forward_display! { (self, cx): &'tcx ty::List> { - p!(write("{{"), comma_sep(self.iter().copied()), write("}}")) + p!(write("{{"), comma_sep(self.iter()), write("}}")) } ty::TypeAndMut<'tcx> { diff --git a/src/librustc_middle/ty/relate.rs b/src/librustc_middle/ty/relate.rs index 594ffbcd836..d507fcbc194 100644 --- a/src/librustc_middle/ty/relate.rs +++ b/src/librustc_middle/ty/relate.rs @@ -143,7 +143,7 @@ pub fn relate_substs>( let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| { let variance = variances.map_or(ty::Invariant, |v| v[i]); - relation.relate_with_variance(variance, a, b) + relation.relate_with_variance(variance, &a, &b) }); Ok(tcx.mk_substs(params)?) @@ -319,7 +319,7 @@ impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> { assert_eq!(a.0.len(), b.0.len()); let tcx = relation.tcx(); - let types = tcx.mk_type_list(a.0.iter().zip(b.0).map(|(a, b)| relation.relate(a, b)))?; + let types = tcx.mk_type_list(a.0.iter().zip(b.0).map(|(a, b)| relation.relate(&a, &b)))?; Ok(GeneratorWitness(types)) } } @@ -633,7 +633,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List> { let tcx = relation.tcx(); let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| { use crate::ty::ExistentialPredicate::*; - match (*ep_a, *ep_b) { + match (ep_a, ep_b) { (Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)), (Projection(ref a), Projection(ref b)) => Ok(Projection(relation.relate(a, b)?)), (AutoTrait(ref a), AutoTrait(ref b)) if a == b => Ok(AutoTrait(*a)), diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index babe0c54801..5cf41982ff2 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -1093,7 +1093,7 @@ where // Look for the first element that changed if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| { let new_t = t.fold_with(folder); - if new_t == *t { None } else { Some((i, new_t)) } + if new_t == t { None } else { Some((i, new_t)) } }) { // An element changed, prepare to intern the resulting list let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len()); diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 0c9eef8093f..8b87a63343c 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -670,7 +670,7 @@ impl<'tcx> List> { pub fn projection_bounds<'a>( &'a self, ) -> impl Iterator> + 'a { - self.iter().filter_map(|predicate| match *predicate { + self.iter().filter_map(|predicate| match predicate { ExistentialPredicate::Projection(projection) => Some(projection), _ => None, }) @@ -678,7 +678,7 @@ impl<'tcx> List> { #[inline] pub fn auto_traits<'a>(&'a self) -> impl Iterator + 'a { - self.iter().filter_map(|predicate| match *predicate { + self.iter().filter_map(|predicate| match predicate { ExistentialPredicate::AutoTrait(did) => Some(did), _ => None, }) @@ -709,7 +709,7 @@ impl<'tcx> Binder<&'tcx List>> { pub fn iter<'a>( &'a self, ) -> impl DoubleEndedIterator>> + 'tcx { - self.skip_binder().iter().cloned().map(Binder::bind) + self.skip_binder().iter().map(Binder::bind) } } diff --git a/src/librustc_middle/ty/subst.rs b/src/librustc_middle/ty/subst.rs index 4d73f8f91ad..1529f1173b3 100644 --- a/src/librustc_middle/ty/subst.rs +++ b/src/librustc_middle/ty/subst.rs @@ -340,11 +340,11 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { target_substs: SubstsRef<'tcx>, ) -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); - tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned()) + tcx.mk_substs(target_substs.iter().chain(self.iter().skip(defs.params.len()))) } pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> { - tcx.mk_substs(self.iter().take(generics.count()).cloned()) + tcx.mk_substs(self.iter().take(generics.count())) } } diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index f9c10488ffb..c2b794ca4bd 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -413,7 +413,7 @@ impl<'tcx> TyCtxt<'tcx> { let result = item_substs .iter() .zip(impl_substs.iter()) - .filter(|&(_, &k)| { + .filter(|&(_, k)| { match k.unpack() { GenericArgKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => { !impl_generics.region_param(ebr, self).pure_wrt_drop @@ -433,7 +433,7 @@ impl<'tcx> TyCtxt<'tcx> { } } }) - .map(|(&item_param, _)| item_param) + .map(|(item_param, _)| item_param) .collect(); debug!("destructor_constraint({:?}) = {:?}", def.did, result); result diff --git a/src/librustc_middle/ty/walk.rs b/src/librustc_middle/ty/walk.rs index 0093c60d768..bf988a43026 100644 --- a/src/librustc_middle/ty/walk.rs +++ b/src/librustc_middle/ty/walk.rs @@ -128,7 +128,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) stack.push(lt.into()); } ty::Projection(data) => { - stack.extend(data.substs.iter().copied().rev()); + stack.extend(data.substs.iter().rev()); } ty::Dynamic(obj, lt) => { stack.push(lt.into()); @@ -143,7 +143,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) } }; - substs.iter().copied().rev().chain(opt_ty.map(|ty| ty.into())) + substs.iter().rev().chain(opt_ty.map(|ty| ty.into())) })); } ty::Adt(_, substs) @@ -152,14 +152,14 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) | ty::Generator(_, substs, _) | ty::Tuple(substs) | ty::FnDef(_, substs) => { - stack.extend(substs.iter().copied().rev()); + stack.extend(substs.iter().rev()); } ty::GeneratorWitness(ts) => { - stack.extend(ts.skip_binder().iter().cloned().rev().map(|ty| ty.into())); + stack.extend(ts.skip_binder().iter().rev().map(|ty| ty.into())); } ty::FnPtr(sig) => { stack.push(sig.skip_binder().output().into()); - stack.extend(sig.skip_binder().inputs().iter().cloned().rev().map(|ty| ty.into())); + stack.extend(sig.skip_binder().inputs().iter().copied().rev().map(|ty| ty.into())); } }, GenericArgKind::Lifetime(_) => {} @@ -174,7 +174,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) | ty::ConstKind::Error => {} ty::ConstKind::Unevaluated(_, substs, _) => { - stack.extend(substs.iter().copied().rev()); + stack.extend(substs.iter().rev()); } } } diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs index e53f50326d3..cadf1ebf1b7 100644 --- a/src/librustc_mir/borrow_check/place_ext.rs +++ b/src/librustc_mir/borrow_check/place_ext.rs @@ -47,7 +47,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { for (i, elem) in self.projection.iter().enumerate() { let proj_base = &self.projection[..i]; - if *elem == ProjectionElem::Deref { + if elem == ProjectionElem::Deref { let ty = Place::ty_from(self.local, proj_base, body, tcx).ty; match ty.kind { ty::Ref(_, _, hir::Mutability::Not) if i == 0 => { diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index 45f77af4aba..809b749f1e7 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -163,8 +163,8 @@ fn place_components_conflict<'tcx>( body, borrow_local, borrow_proj_base, - borrow_c, - access_c, + &borrow_c, + &access_c, bias, ) { Overlap::Arbitrary => { @@ -420,24 +420,24 @@ fn place_projection_conflict<'tcx>( } } ( - ProjectionElem::ConstantIndex { + &ProjectionElem::ConstantIndex { offset: offset_from_begin, min_length: min_length1, from_end: false, }, - ProjectionElem::ConstantIndex { + &ProjectionElem::ConstantIndex { offset: offset_from_end, min_length: min_length2, from_end: true, }, ) | ( - ProjectionElem::ConstantIndex { + &ProjectionElem::ConstantIndex { offset: offset_from_end, min_length: min_length1, from_end: true, }, - ProjectionElem::ConstantIndex { + &ProjectionElem::ConstantIndex { offset: offset_from_begin, min_length: min_length2, from_end: false, @@ -449,7 +449,7 @@ fn place_projection_conflict<'tcx>( // element (like -1 in Python) and `min_length` the first. // Therefore, `min_length - offset_from_end` gives the minimal possible // offset from the beginning - if *offset_from_begin >= *min_length - *offset_from_end { + if offset_from_begin >= min_length - offset_from_end { debug!("place_element_conflict: DISJOINT-OR-EQ-ARRAY-CONSTANT-INDEX-FE"); Overlap::EqualOrDisjoint } else { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index bdbce1de745..1a64dcbf439 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -497,7 +497,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { return PlaceTy::from_ty(self.tcx().types.err); } } - place_ty = self.sanitize_projection(place_ty, elem, place, location) + place_ty = self.sanitize_projection(place_ty, &elem, place, location) } if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 0f2760b3f3b..b89884a4492 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -158,7 +158,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { }; if union_path.is_none() { - base = self.add_move_path(base, elem, |tcx| Place { + base = self.add_move_path(base, &elem, |tcx| Place { local: place.local, projection: tcx.intern_place_elems(&place.projection[..i + 1]), }); diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index a3caa2048a1..8edfbbb3c22 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -466,7 +466,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let op = place .projection .iter() - .try_fold(base_op, |op, elem| self.operand_projection(op, elem))?; + .try_fold(base_op, |op, elem| self.operand_projection(op, &elem))?; trace!("eval_place_to_op: got {:?}", *op); Ok(op) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 6dadb8e4c67..4943e148731 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -634,7 +634,7 @@ where }; for elem in place.projection.iter() { - place_ty = self.place_projection(place_ty, elem)? + place_ty = self.place_projection(place_ty, &elem)? } self.dump_place(place_ty.place); diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 081f6435d9d..c75e8414e8c 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -449,7 +449,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { let type_length = instance .substs .iter() - .flat_map(|&arg| arg.walk()) + .flat_map(|arg| arg.walk()) .filter(|arg| match arg.unpack() { GenericArgKind::Type(_) | GenericArgKind::Const(_) => true, GenericArgKind::Lifetime(_) => false, diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 5f8104e7934..846ae55dffe 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -132,7 +132,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> { for elem in place.projection.iter() { if let PlaceElem::Index(local) = elem { - assert_ne!(*local, SELF_ARG); + assert_ne!(local, SELF_ARG); } } } @@ -171,7 +171,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> { for elem in place.projection.iter() { if let PlaceElem::Index(local) = elem { - assert_ne!(*local, SELF_ARG); + assert_ne!(local, SELF_ARG); } } } diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index 1071a4c97df..147c09d8f3a 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -1042,7 +1042,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { matched_candidates.iter().flat_map(|candidate| &candidate.bindings) { if let Some(i) = - source.projection.iter().rposition(|elem| *elem == ProjectionElem::Deref) + source.projection.iter().rposition(|elem| elem == ProjectionElem::Deref) { let proj_base = &source.projection[..i]; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 9a63e39f535..cb896810951 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -176,7 +176,7 @@ where // All traits in the list are considered the "primary" part of the type // and are visited by shallow visitors. for predicate in *predicates.skip_binder() { - let trait_ref = match *predicate { + let trait_ref = match predicate { ty::ExistentialPredicate::Trait(trait_ref) => trait_ref, ty::ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx), ty::ExistentialPredicate::AutoTrait(def_id) => { diff --git a/src/librustc_symbol_mangling/v0.rs b/src/librustc_symbol_mangling/v0.rs index 3b439e09a9d..1a536b6a429 100644 --- a/src/librustc_symbol_mangling/v0.rs +++ b/src/librustc_symbol_mangling/v0.rs @@ -477,7 +477,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { predicates: &'tcx ty::List>, ) -> Result { for predicate in predicates { - match *predicate { + match predicate { ty::ExistentialPredicate::Trait(trait_ref) => { // Use a type that can't appear in defaults of type parameters. let dummy_self = self.tcx.mk_ty_infer(ty::FreshTy(0)); diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 2544e4ddea2..767640bcd3c 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -647,7 +647,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // shifting. let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id); let map: FxHashMap, GenericArg<'tcx>> = - substs.iter().enumerate().map(|(index, subst)| (*subst, id_substs[index])).collect(); + substs.iter().enumerate().map(|(index, subst)| (subst, id_substs[index])).collect(); // Convert the type from the function into a type valid outside // the function, by replacing invalid regions with 'static, @@ -891,7 +891,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { // during codegen. let generics = self.tcx.generics_of(def_id); - let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| { + let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, kind)| { if index < generics.parent_count { // Accommodate missing regions in the parent kinds... self.fold_kind_mapping_missing_regions_to_empty(kind) @@ -906,7 +906,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { ty::Generator(def_id, substs, movability) => { let generics = self.tcx.generics_of(def_id); - let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| { + let substs = self.tcx.mk_substs(substs.iter().enumerate().map(|(index, kind)| { if index < generics.parent_count { // Accommodate missing regions in the parent kinds... self.fold_kind_mapping_missing_regions_to_empty(kind) diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index 0d986e60ff4..433e1e46f6b 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -281,9 +281,8 @@ impl AutoTraitFinder<'tcx> { }, })); - let computed_preds = param_env.caller_bounds.iter().cloned(); - let mut user_computed_preds: FxHashSet<_> = - user_env.caller_bounds.iter().cloned().collect(); + let computed_preds = param_env.caller_bounds.iter(); + let mut user_computed_preds: FxHashSet<_> = user_env.caller_bounds.iter().collect(); let mut new_env = param_env; let dummy_cause = ObligationCause::dummy(); diff --git a/src/librustc_trait_selection/traits/chalk_fulfill.rs b/src/librustc_trait_selection/traits/chalk_fulfill.rs index be0512dcac9..2d4d582c939 100644 --- a/src/librustc_trait_selection/traits/chalk_fulfill.rs +++ b/src/librustc_trait_selection/traits/chalk_fulfill.rs @@ -87,7 +87,7 @@ fn environment<'tcx>( NodeKind::TraitImpl => { let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl"); - inputs.extend(trait_ref.substs.iter().flat_map(|&arg| arg.walk())); + inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk())); } // In an inherent impl, we assume that the receiver type and all its diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 3daa9109aaf..a5b9fd8f8d8 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -302,7 +302,7 @@ pub fn normalize_param_env_or_error<'tcx>( ); let mut predicates: Vec<_> = - util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.into_iter().cloned()) + util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.into_iter()) .map(|obligation| obligation.predicate) .collect(); diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index b2d684e674f..5befc797a51 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -658,7 +658,6 @@ fn receiver_is_dispatchable<'tcx>( let caller_bounds: Vec> = param_env .caller_bounds .iter() - .cloned() .chain(iter::once(unsize_predicate)) .chain(iter::once(trait_predicate)) .collect(); diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index 72f089ae2a7..cd5d0be003a 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -872,7 +872,7 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>( obligation_trait_ref, candidate_set, ProjectionTyCandidate::ParamEnv, - obligation.param_env.caller_bounds.iter().cloned(), + obligation.param_env.caller_bounds.iter(), ); } diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 05402fe3c19..82a3873f406 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -3154,7 +3154,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check that the source struct with the target's // unsizing parameters is equal to the target. - let substs = tcx.mk_substs(substs_a.iter().enumerate().map(|(i, &k)| { + let substs = tcx.mk_substs(substs_a.iter().enumerate().map(|(i, k)| { if unsizing_params.contains(i as u32) { substs_b[i] } else { k } })); let new_struct = tcx.mk_adt(def, substs); diff --git a/src/librustc_ty/needs_drop.rs b/src/librustc_ty/needs_drop.rs index e94a47f079a..1b059fa3dbd 100644 --- a/src/librustc_ty/needs_drop.rs +++ b/src/librustc_ty/needs_drop.rs @@ -11,7 +11,7 @@ type NeedsDropResult = Result; fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { let adt_fields = - move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter().copied()); + move |adt_def: &ty::AdtDef| tcx.adt_drop_tys(adt_def.did).map(|tys| tys.iter()); // If we don't know a type doesn't need drop, for example if it's a type // parameter without a `Copy` bound, then we conservatively return that it // needs drop. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c452859414c..0c8613d82db 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2769,7 +2769,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { ty::GenericPredicates { parent: None, predicates: tcx.arena.alloc_from_iter(self.param_env.caller_bounds.iter().filter_map( - |&predicate| match predicate.kind() { + |predicate| match predicate.kind() { ty::PredicateKind::Trait(ref data, _) if data.skip_binder().self_ty().is_param(index) => { diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 06e2d99983b..e154184f182 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -900,7 +900,7 @@ fn check_opaque_types<'fcx, 'tcx>( if may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) { trace!("check_opaque_types: may define, generics={:#?}", generics); let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default(); - for (i, &arg) in substs.iter().enumerate() { + for (i, arg) in substs.iter().enumerate() { let arg_is_param = match arg.unpack() { GenericArgKind::Type(ty) => matches!(ty.kind, ty::Param(_)), diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index b262ccf913a..ded27605d15 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -229,7 +229,7 @@ fn unconstrained_parent_impl_substs<'tcx>( .iter() .enumerate() .filter(|&(idx, _)| !constrained_params.contains(&(idx as u32))) - .map(|(_, arg)| *arg) + .map(|(_, arg)| arg) .collect() } diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 3a680f55c8c..e42cf3ef32a 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -291,7 +291,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } ty::Tuple(subtys) => { - for &subty in subtys { + for subty in subtys { self.add_constraints_from_ty(current, subty.expect_ty(), variance); } } diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 60c53600543..1621c7f947c 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) + let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { @@ -179,7 +179,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { .substs .iter() .skip(1) - .cloned() .collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), ty_params) })