Skip to content

Commit 2dfaa86

Browse files
committed
add comment dyn-iterator-deref-in-for-loop.rs
1 parent 79082b9 commit 2dfaa86

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

tests/ui/traits/dyn-iterator-deref-in-for-loop.current.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
2-
--> $DIR/issue-20605.rs:6:17
2+
--> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17
33
|
4-
LL | for item in *things { *item = 0 }
4+
LL | for item in *things {
55
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
66
|
77
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
88
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
99
help: consider mutably borrowing here
1010
|
11-
LL | for item in &mut *things { *item = 0 }
11+
LL | for item in &mut *things {
1212
| ++++
1313

1414
error: aborting due to 1 previous error

tests/ui/traits/dyn-iterator-deref-in-for-loop.next.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
2-
--> $DIR/issue-20605.rs:6:17
2+
--> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17
33
|
4-
LL | for item in *things { *item = 0 }
4+
LL | for item in *things {
55
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
66
|
77
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
88
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
99
help: consider mutably borrowing here
1010
|
11-
LL | for item in &mut *things { *item = 0 }
11+
LL | for item in &mut *things {
1212
| ++++
1313

1414
error: aborting due to 1 previous error
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
//! Tests that dereferencing a Box<dyn Iterator> in a for loop correctly yields an error,
2+
//! as the unsized trait object does not implement IntoIterator.
3+
//! regression test for <https://github.com/rust-lang/rust/issues/20605>
14
//@ revisions: current next
25
//@ ignore-compare-mode-next-solver (explicit revisions)
36
//@[next] compile-flags: -Znext-solver
47

5-
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
6-
for item in *things { *item = 0 }
7-
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
8+
fn changer<'a>(mut things: Box<dyn Iterator<Item = &'a mut u8>>) {
9+
for item in *things {
10+
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
11+
*item = 0
12+
}
813
}
914

1015
fn main() {}

0 commit comments

Comments
 (0)