Skip to content

Commit 49d5bef

Browse files
committed
Expand iterator chain test
1 parent bc60d50 commit 49d5bef

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/test/ui/iterators/invalid-iterator-chain.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ fn main() {
99
"{}",
1010
vec![0, 1] //~ ERROR E0277
1111
.iter()
12+
.map(|x| x * 2)
13+
.map(|x| x as f64)
14+
.map(|x| x as i64)
15+
.filter(|x| *x > 0)
16+
.map(|x| { x + 1 })
1217
.map(|x| { x; })
1318
.sum::<i32>(),
1419
);

src/test/ui/iterators/invalid-iterator-chain.stderr

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ error[E0277]: the trait bound `i32: Sum<()>` is not satisfied
3434
|
3535
LL | / vec![0, 1]
3636
LL | | .iter()
37+
LL | | .map(|x| x * 2)
38+
LL | | .map(|x| x as f64)
39+
... |
40+
LL | | .map(|x| { x + 1 })
3741
LL | | .map(|x| { x; })
3842
| |____________________________^ the trait `Sum<()>` is not implemented for `i32`
3943
LL | .sum::<i32>(),
@@ -42,13 +46,23 @@ LL | .sum::<i32>(),
4246
= help: the following other types implement trait `Sum<A>`:
4347
<i32 as Sum<&'a i32>>
4448
<i32 as Sum>
45-
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>`
46-
--> $DIR/invalid-iterator-chain.rs:12:14
49+
note: the expression is of type `Map<Map<Filter<Map<Map<Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>, [closure@$DIR/invalid-iterator-chain.rs:13:18: 13:21]>, [closure@$DIR/invalid-iterator-chain.rs:14:18: 14:21]>, [closure@$DIR/invalid-iterator-chain.rs:15:21: 15:24]>, [closure@$DIR/invalid-iterator-chain.rs:16:18: 16:21]>, [closure@$DIR/invalid-iterator-chain.rs:17:18: 17:21]>`
50+
--> $DIR/invalid-iterator-chain.rs:17:14
4751
|
4852
LL | vec![0, 1]
4953
| ---------- this expression has type `Vec<{integer}>`
5054
LL | .iter()
5155
| ------ associated type `std::iter::Iterator::Item` is `&{integer}` here
56+
LL | .map(|x| x * 2)
57+
| -------------- associated type `std::iter::Iterator::Item` is `{integer}` here
58+
LL | .map(|x| x as f64)
59+
| ----------------- associated type `std::iter::Iterator::Item` is `f64` here
60+
LL | .map(|x| x as i64)
61+
| ----------------- associated type `std::iter::Iterator::Item` is `i64` here
62+
LL | .filter(|x| *x > 0)
63+
| ------------------ associated type `std::iter::Iterator::Item` is `i64` here
64+
LL | .map(|x| { x + 1 })
65+
| ------------------ associated type `std::iter::Iterator::Item` is `i64` here
5266
LL | .map(|x| { x; })
5367
| ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here
5468
note: required by a bound in `std::iter::Iterator::sum`
@@ -58,7 +72,7 @@ LL | S: Sum<Self::Item>,
5872
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
5973

6074
error[E0277]: the trait bound `i32: Sum<()>` is not satisfied
61-
--> $DIR/invalid-iterator-chain.rs:15:20
75+
--> $DIR/invalid-iterator-chain.rs:20:20
6276
|
6377
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
6478
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call
@@ -68,8 +82,8 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
6882
= help: the following other types implement trait `Sum<A>`:
6983
<i32 as Sum<&'a i32>>
7084
<i32 as Sum>
71-
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:15:42: 15:45]>`
72-
--> $DIR/invalid-iterator-chain.rs:15:38
85+
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:20:42: 20:45]>`
86+
--> $DIR/invalid-iterator-chain.rs:20:38
7387
|
7488
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
7589
| ---------- ------ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here
@@ -83,7 +97,7 @@ LL | S: Sum<Self::Item>,
8397
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
8498

8599
error[E0277]: the trait bound `i32: Sum<&()>` is not satisfied
86-
--> $DIR/invalid-iterator-chain.rs:16:20
100+
--> $DIR/invalid-iterator-chain.rs:21:20
87101
|
88102
LL | println!("{}", vec![(), ()].iter().sum::<i32>());
89103
| ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call
@@ -94,7 +108,7 @@ LL | println!("{}", vec![(), ()].iter().sum::<i32>());
94108
<i32 as Sum<&'a i32>>
95109
<i32 as Sum>
96110
note: the expression is of type `std::slice::Iter<'_, ()>`
97-
--> $DIR/invalid-iterator-chain.rs:16:33
111+
--> $DIR/invalid-iterator-chain.rs:21:33
98112
|
99113
LL | println!("{}", vec![(), ()].iter().sum::<i32>());
100114
| ------------ ^^^^^^ associated type `std::iter::Iterator::Item` is `&()` here

0 commit comments

Comments
 (0)