Skip to content

Commit d6ff916

Browse files
committed
test: add case for mutating iterator
Note that this incorrectly suggests a shared borrow, but at least we know it's happening.
1 parent f23003d commit d6ff916

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/test/ui/suggestions/slice-issue-87994.rs

+9
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ fn main() {
44
//~^ ERROR [i32]` is not an iterator [E0277]
55
//~^^ ERROR known at compilation time
66
}
7+
struct K {
8+
n: i32,
9+
}
10+
let mut v2 = vec![K { n: 1 }, K { n: 1 }, K { n: 1 }];
11+
for i2 in v2[1..] {
12+
//~^ ERROR [K]` is not an iterator [E0277]
13+
//~^^ ERROR known at compilation time
14+
i2.n = 2;
15+
}
716
}

src/test/ui/suggestions/slice-issue-87994.stderr

+35-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ note: required by `into_iter`
3232
LL | fn into_iter(self) -> Self::IntoIter;
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

35-
error: aborting due to 2 previous errors
35+
error[E0277]: the size for values of type `[K]` cannot be known at compilation time
36+
--> $DIR/slice-issue-87994.rs:11:13
37+
|
38+
LL | for i2 in v2[1..] {
39+
| ^^^^^^^
40+
| |
41+
| expected an implementor of trait `IntoIterator`
42+
| help: consider borrowing here: `&v2[1..]`
43+
|
44+
= note: the trait bound `[K]: IntoIterator` is not satisfied
45+
= note: required because of the requirements on the impl of `IntoIterator` for `[K]`
46+
note: required by `into_iter`
47+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
48+
|
49+
LL | fn into_iter(self) -> Self::IntoIter;
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
52+
error[E0277]: `[K]` is not an iterator
53+
--> $DIR/slice-issue-87994.rs:11:13
54+
|
55+
LL | for i2 in v2[1..] {
56+
| ^^^^^^^
57+
| |
58+
| expected an implementor of trait `IntoIterator`
59+
| help: consider borrowing here: `&v2[1..]`
60+
|
61+
= note: the trait bound `[K]: IntoIterator` is not satisfied
62+
= note: required because of the requirements on the impl of `IntoIterator` for `[K]`
63+
note: required by `into_iter`
64+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
65+
|
66+
LL | fn into_iter(self) -> Self::IntoIter;
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
69+
error: aborting due to 4 previous errors
3670

3771
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)