Skip to content

Commit 073f5e2

Browse files
committed
Updated tests/ui/for-loop-while/iter-from-mac-call.rs
1 parent 416ae00 commit 073f5e2

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
macro_rules! deref {
2-
($e:expr) => { *$e };
3-
}
1+
//! Tests for trait/type errors when dereferencing via macro in a for loop.
42
5-
fn f1<'a>(mut iter: Box<dyn Iterator<Item=&'a mut u8>>) {
6-
for item in deref!(iter) { *item = 0 }
7-
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
3+
macro_rules! deref {
4+
($e:expr) => {
5+
*$e
6+
};
87
}
98

10-
fn f2(x: &mut i32) {
9+
fn f1(x: &mut i32) {
1110
for _item in deref!(x) {}
1211
//~^ ERROR `i32` is not an iterator
1312
}
1413

1514
struct Wrapped(i32);
1615

1716
macro_rules! borrow_deref {
18-
($e:expr) => { &mut *$e };
17+
($e:expr) => {
18+
&mut *$e
19+
};
1920
}
2021

21-
fn f3<'a>(mut iter: Box<dyn Iterator<Item=&'a mut i32>>) {
22-
for Wrapped(item) in borrow_deref!(iter) { *item = 0 }
23-
//~^ ERROR mismatched types
22+
fn f2<'a>(mut iter: Box<dyn Iterator<Item = &'a mut i32>>) {
23+
for Wrapped(item) in borrow_deref!(iter) {
24+
//~^ ERROR mismatched types
25+
*item = 0
26+
}
2427
}
2528

2629
fn main() {}
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
2-
--> $DIR/iter_from_mac_call.rs:6:17
3-
|
4-
LL | for item in deref!(iter) { *item = 0 }
5-
| ^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
6-
|
7-
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
8-
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
9-
help: consider mutably borrowing here
10-
|
11-
LL | for item in &mut deref!(iter) { *item = 0 }
12-
| ++++
13-
141
error[E0277]: `i32` is not an iterator
15-
--> $DIR/iter_from_mac_call.rs:11:18
2+
--> $DIR/iter-from-mac-call.rs:10:18
163
|
174
LL | for _item in deref!(x) {}
185
| ^^^^^^^^^ `i32` is not an iterator
@@ -22,14 +9,14 @@ LL | for _item in deref!(x) {}
229
= note: required for `i32` to implement `IntoIterator`
2310

2411
error[E0308]: mismatched types
25-
--> $DIR/iter_from_mac_call.rs:22:9
12+
--> $DIR/iter-from-mac-call.rs:23:9
2613
|
27-
LL | for Wrapped(item) in borrow_deref!(iter) { *item = 0 }
14+
LL | for Wrapped(item) in borrow_deref!(iter) {
2815
| ^^^^^^^^^^^^^ ------------------- this is an iterator with items of type `&mut i32`
2916
| |
3017
| expected `i32`, found `Wrapped`
3118

32-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
3320

3421
Some errors have detailed explanations: E0277, E0308.
3522
For more information about an error, try `rustc --explain E0277`.

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)