Updated tests/ui/for-loop-while/iter-from-mac-call.rs

This commit is contained in:
reddevilmidzy 2025-12-02 11:25:36 +09:00
parent 416ae00e31
commit 073f5e29f1
5 changed files with 32 additions and 37 deletions

View file

@ -1,13 +1,12 @@
//! Tests for trait/type errors when dereferencing via macro in a for loop.
macro_rules! deref {
($e:expr) => { *$e };
($e:expr) => {
*$e
};
}
fn f1<'a>(mut iter: Box<dyn Iterator<Item=&'a mut u8>>) {
for item in deref!(iter) { *item = 0 }
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
}
fn f2(x: &mut i32) {
fn f1(x: &mut i32) {
for _item in deref!(x) {}
//~^ ERROR `i32` is not an iterator
}
@ -15,12 +14,16 @@ fn f2(x: &mut i32) {
struct Wrapped(i32);
macro_rules! borrow_deref {
($e:expr) => { &mut *$e };
($e:expr) => {
&mut *$e
};
}
fn f3<'a>(mut iter: Box<dyn Iterator<Item=&'a mut i32>>) {
for Wrapped(item) in borrow_deref!(iter) { *item = 0 }
//~^ ERROR mismatched types
fn f2<'a>(mut iter: Box<dyn Iterator<Item = &'a mut i32>>) {
for Wrapped(item) in borrow_deref!(iter) {
//~^ ERROR mismatched types
*item = 0
}
}
fn main() {}

View file

@ -1,18 +1,5 @@
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
--> $DIR/iter_from_mac_call.rs:6:17
|
LL | for item in deref!(iter) { *item = 0 }
| ^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
help: consider mutably borrowing here
|
LL | for item in &mut deref!(iter) { *item = 0 }
| ++++
error[E0277]: `i32` is not an iterator
--> $DIR/iter_from_mac_call.rs:11:18
--> $DIR/iter-from-mac-call.rs:10:18
|
LL | for _item in deref!(x) {}
| ^^^^^^^^^ `i32` is not an iterator
@ -22,14 +9,14 @@ LL | for _item in deref!(x) {}
= note: required for `i32` to implement `IntoIterator`
error[E0308]: mismatched types
--> $DIR/iter_from_mac_call.rs:22:9
--> $DIR/iter-from-mac-call.rs:23:9
|
LL | for Wrapped(item) in borrow_deref!(iter) { *item = 0 }
LL | for Wrapped(item) in borrow_deref!(iter) {
| ^^^^^^^^^^^^^ ------------------- this is an iterator with items of type `&mut i32`
| |
| expected `i32`, found `Wrapped`
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,14 +1,14 @@
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
--> $DIR/issue-20605.rs:6:17
--> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17
|
LL | for item in *things { *item = 0 }
LL | for item in *things {
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
help: consider mutably borrowing here
|
LL | for item in &mut *things { *item = 0 }
LL | for item in &mut *things {
| ++++
error: aborting due to 1 previous error

View file

@ -1,14 +1,14 @@
error[E0277]: `dyn Iterator<Item = &'a mut u8>` is not an iterator
--> $DIR/issue-20605.rs:6:17
--> $DIR/dyn-iterator-deref-in-for-loop.rs:9:17
|
LL | for item in *things { *item = 0 }
LL | for item in *things {
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`
help: consider mutably borrowing here
|
LL | for item in &mut *things { *item = 0 }
LL | for item in &mut *things {
| ++++
error: aborting due to 1 previous error

View file

@ -1,10 +1,15 @@
//! Tests that dereferencing a Box<dyn Iterator> in a for loop correctly yields an error,
//! as the unsized trait object does not implement IntoIterator.
//! regression test for <https://github.com/rust-lang/rust/issues/20605>
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
for item in *things { *item = 0 }
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
fn changer<'a>(mut things: Box<dyn Iterator<Item = &'a mut u8>>) {
for item in *things {
//~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
*item = 0
}
}
fn main() {}