forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests and update existing tests
- Loading branch information
Showing
7 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// check-pass | ||
|
||
#![feature(async_for_loop)] | ||
|
||
// Make sure we don't break `for await` loops in the 2015 edition, where `await` was allowed as an | ||
// identifier. | ||
|
||
fn main() { | ||
for await in 0..3 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// edition: 2021 | ||
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)] | ||
|
||
use std::future::Future; | ||
|
||
// a test to make sure `for await` consumes the iterator | ||
|
||
async fn real_main() { | ||
let iter = core::async_iter::from_iter(0..3); | ||
let mut count = 0; | ||
for await i in iter { | ||
} | ||
// make sure iter has been moved and we can't iterate over it again. | ||
for await i in iter { | ||
//~^ ERROR: use of moved value: `iter` | ||
} | ||
} | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0382]: use of moved value: `iter` | ||
--> $DIR/for-await-consumes-iter.rs:14:20 | ||
| | ||
LL | let iter = core::async_iter::from_iter(0..3); | ||
| ---- move occurs because `iter` has type `FromIter<std::ops::Range<i32>>`, which does not implement the `Copy` trait | ||
LL | let mut count = 0; | ||
LL | for await i in iter { | ||
| ------------------- | ||
| | | | ||
| | value moved here | ||
| inside of this loop | ||
... | ||
LL | for await i in iter { | ||
| ^^^^ value used here after move | ||
| | ||
help: consider cloning the value if the performance cost is acceptable | ||
| | ||
LL | for await i in iter.clone() { | ||
| ++++++++ | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | for await i in ref iter { | ||
| +++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// run-pass | ||
// edition: 2024 | ||
// compile-flags: -Zunstable-options | ||
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker, | ||
gen_blocks)] | ||
|
||
use std::future::Future; | ||
|
||
async gen fn async_iter() -> i32 { | ||
let iter = core::async_iter::from_iter(0..3); | ||
for await i in iter { | ||
yield i + 1; | ||
} | ||
} | ||
|
||
// make sure a simple for await loop works | ||
async fn real_main() { | ||
let mut count = 1; | ||
for await i in async_iter() { | ||
assert_eq!(i, count); | ||
count += 1; | ||
} | ||
assert_eq!(count, 4); | ||
} | ||
|
||
fn main() { | ||
let future = real_main(); | ||
let waker = std::task::Waker::noop(); | ||
let mut cx = &mut core::task::Context::from_waker(&waker); | ||
let mut future = core::pin::pin!(future); | ||
while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {} | ||
} |