Skip to content

Commit da57ced

Browse files
committed
iterate List by value
1 parent 647ae50 commit da57ced

File tree

40 files changed

+82
-72
lines changed

40 files changed

+82
-72
lines changed

src/librustc_codegen_ssa/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn push_debuginfo_type_name<'tcx>(
4848
}
4949
ty::Tuple(component_types) => {
5050
output.push('(');
51-
for &component_type in component_types {
51+
for component_type in component_types {
5252
push_debuginfo_type_name(tcx, component_type.expect_ty(), true, output, visited);
5353
output.push_str(", ");
5454
}

src/librustc_infer/infer/canonical/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
8787
) -> CanonicalVarValues<'tcx> {
8888
let var_values: IndexVec<BoundVar, GenericArg<'tcx>> = variables
8989
.iter()
90-
.map(|info| self.instantiate_canonical_var(span, *info, &universe_map))
90+
.map(|info| self.instantiate_canonical_var(span, info, &universe_map))
9191
.collect();
9292

9393
CanonicalVarValues { var_values }

src/librustc_infer/infer/canonical/query_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
464464
if info.is_existential() {
465465
match opt_values[BoundVar::new(index)] {
466466
Some(k) => k,
467-
None => self.instantiate_canonical_var(cause.span, *info, |u| {
467+
None => self.instantiate_canonical_var(cause.span, info, |u| {
468468
universe_map[u.as_usize()]
469469
}),
470470
}
471471
} else {
472-
self.instantiate_canonical_var(cause.span, *info, |u| {
472+
self.instantiate_canonical_var(cause.span, info, |u| {
473473
universe_map[u.as_usize()]
474474
})
475475
}

src/librustc_infer/infer/outlives/verify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
5050
// for further background and discussion.
5151
let mut bounds = substs
5252
.iter()
53-
.filter_map(|&child| match child.unpack() {
53+
.filter_map(|child| match child.unpack() {
5454
GenericArgKind::Type(ty) => Some(self.type_bound(ty)),
5555
GenericArgKind::Lifetime(_) => None,
5656
GenericArgKind::Const(_) => Some(self.recursive_bound(child)),
@@ -223,8 +223,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
223223
// like `T` and `T::Item`. It may not work as well for things
224224
// like `<T as Foo<'a>>::Item`.
225225
let c_b = self.param_env.caller_bounds;
226-
let param_bounds =
227-
self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter().copied());
226+
let param_bounds = self.collect_outlives_from_predicate_list(&compare_ty, c_b.into_iter());
228227

229228
// Next, collect regions we scraped from the well-formedness
230229
// constraints in the fn signature. To do that, we walk the list

src/librustc_middle/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,10 +2077,10 @@ impl Debug for Place<'_> {
20772077
ProjectionElem::ConstantIndex { offset, min_length, from_end: true } => {
20782078
write!(fmt, "[-{:?} of {:?}]", offset, min_length)?;
20792079
}
2080-
ProjectionElem::Subslice { from, to, from_end: true } if *to == 0 => {
2080+
ProjectionElem::Subslice { from, to, from_end: true } if to == 0 => {
20812081
write!(fmt, "[{:?}:]", from)?;
20822082
}
2083-
ProjectionElem::Subslice { from, to, from_end: true } if *from == 0 => {
2083+
ProjectionElem::Subslice { from, to, from_end: true } if from == 0 => {
20842084
write!(fmt, "[:-{:?}]", to)?;
20852085
}
20862086
ProjectionElem::Subslice { from, to, from_end: true } => {

src/librustc_middle/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl FlagComputation {
129129
&ty::Dynamic(ref obj, r) => {
130130
let mut computation = FlagComputation::new();
131131
for predicate in obj.skip_binder().iter() {
132-
match *predicate {
132+
match predicate {
133133
ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs),
134134
ty::ExistentialPredicate::Projection(p) => {
135135
let mut proj_computation = FlagComputation::new();

src/librustc_middle/ty/list.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_serialize::{Encodable, Encoder};
55
use std::cmp::{self, Ordering};
66
use std::fmt;
77
use std::hash::{Hash, Hasher};
8+
use std::iter;
89
use std::mem;
910
use std::ops::Deref;
1011
use std::ptr;
@@ -21,6 +22,10 @@ extern "C" {
2122
/// the same contents can exist in the same context.
2223
/// This means we can use pointer for both
2324
/// equality comparisons and hashing.
25+
///
26+
/// Unlike slices, The types contained in `List` are expected to be `Copy`
27+
/// and iterating over a `List` returns `T` instead of a reference.
28+
///
2429
/// Note: `Slice` was already taken by the `Ty`.
2530
#[repr(C)]
2631
pub struct List<T> {
@@ -61,6 +66,15 @@ impl<T: Copy> List<T> {
6166
result
6267
}
6368
}
69+
70+
// If this method didn't exist, we would use `slice.iter` due to
71+
// deref coercion.
72+
//
73+
// This would be weird, as `self.into_iter` iterates over `T` directly.
74+
#[inline(always)]
75+
pub fn iter(&self) -> <&'_ List<T> as IntoIterator>::IntoIter {
76+
self.into_iter()
77+
}
6478
}
6579

6680
impl<T: fmt::Debug> fmt::Debug for List<T> {
@@ -128,12 +142,12 @@ impl<T> AsRef<[T]> for List<T> {
128142
}
129143
}
130144

131-
impl<'a, T> IntoIterator for &'a List<T> {
132-
type Item = &'a T;
133-
type IntoIter = <&'a [T] as IntoIterator>::IntoIter;
145+
impl<'a, T: Copy> IntoIterator for &'a List<T> {
146+
type Item = T;
147+
type IntoIter = iter::Copied<<&'a [T] as IntoIterator>::IntoIter>;
134148
#[inline(always)]
135149
fn into_iter(self) -> Self::IntoIter {
136-
self[..].iter()
150+
self[..].iter().copied()
137151
}
138152
}
139153

src/librustc_middle/ty/outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
7070
// consistent with previous (accidental) behavior.
7171
// See https://github.com/rust-lang/rust/issues/70917
7272
// for further background and discussion.
73-
for &child in substs {
73+
for child in substs {
7474
match child.unpack() {
7575
GenericArgKind::Type(ty) => {
7676
compute_components(tcx, ty, out);

src/librustc_middle/ty/print/obsolete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl DefPathBasedNames<'tcx> {
4747
}
4848
ty::Tuple(component_types) => {
4949
output.push('(');
50-
for &component_type in component_types {
50+
for component_type in component_types {
5151
self.push_type_name(component_type.expect_ty(), output, debug);
5252
output.push_str(", ");
5353
}

src/librustc_middle/ty/print/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ pub trait PrettyPrinter<'tcx>:
495495
}
496496
ty::Never => p!(write("!")),
497497
ty::Tuple(ref tys) => {
498-
p!(write("("), comma_sep(tys.iter().copied()));
498+
p!(write("("), comma_sep(tys.iter()));
499499
if tys.len() == 1 {
500500
p!(write(","));
501501
}
@@ -560,7 +560,7 @@ pub trait PrettyPrinter<'tcx>:
560560
// FIXME(eddyb) print this with `print_def_path`.
561561
if !substs.is_empty() {
562562
p!(write("::"));
563-
p!(generic_delimiters(|cx| cx.comma_sep(substs.iter().copied())));
563+
p!(generic_delimiters(|cx| cx.comma_sep(substs.iter())));
564564
}
565565
return Ok(self);
566566
}
@@ -1935,7 +1935,7 @@ define_print_and_forward_display! {
19351935
(self, cx):
19361936

19371937
&'tcx ty::List<Ty<'tcx>> {
1938-
p!(write("{{"), comma_sep(self.iter().copied()), write("}}"))
1938+
p!(write("{{"), comma_sep(self.iter()), write("}}"))
19391939
}
19401940

19411941
ty::TypeAndMut<'tcx> {

0 commit comments

Comments
 (0)