diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-09-25 09:32:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-25 09:32:08 +0200 |
| commit | 11b45102024cbd77cc319fefbfaa21aa35ba8c31 (patch) | |
| tree | 16d493b868ebf9b9f1a89142d6b9740d90c68aaa /src | |
| parent | 16de1fddee347c326dc4c7f07fa12dd714efd63e (diff) | |
| parent | e87fcc026b4e31ffd352a035e58d78142c577dea (diff) | |
| download | rust-11b45102024cbd77cc319fefbfaa21aa35ba8c31.tar.gz rust-11b45102024cbd77cc319fefbfaa21aa35ba8c31.zip | |
Rollup merge of #102161 - compiler-errors:issue-102138, r=tmandry
Resolve async fn signature even without body (e.g., in trait) Fixes #102138 This "bail if no body" behavior was introduced in #69539 to fix #69401, but that ICE does not reproduce any more. The error message changes a bit, but that's all, and I don't think it's a particularly diagnostic bad regression.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/async-await/in-trait/issue-102138.rs | 46 | ||||
| -rw-r--r-- | src/test/ui/resolve/name-collision-in-trait-fn-sig.rs | 11 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/test/ui/async-await/in-trait/issue-102138.rs b/src/test/ui/async-await/in-trait/issue-102138.rs new file mode 100644 index 00000000000..f61b34ed99e --- /dev/null +++ b/src/test/ui/async-await/in-trait/issue-102138.rs @@ -0,0 +1,46 @@ +// check-pass +// edition:2021 + +#![feature(async_fn_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; + +async fn yield_now() {} + +trait AsyncIterator { + type Item; + async fn next(&mut self) -> Option<Self::Item>; +} + +struct YieldingRange { + counter: u32, + stop: u32, +} + +impl AsyncIterator for YieldingRange { + type Item = u32; + + async fn next(&mut self) -> Option<Self::Item> { + if self.counter == self.stop { + None + } else { + let c = self.counter; + self.counter += 1; + yield_now().await; + Some(c) + } + } +} + +async fn async_main() { + let mut x = YieldingRange { counter: 0, stop: 10 }; + + while let Some(v) = x.next().await { + println!("Hi: {v}"); + } +} + +fn main() { + let _ = async_main(); +} diff --git a/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs new file mode 100644 index 00000000000..fba4ffa1c6e --- /dev/null +++ b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs @@ -0,0 +1,11 @@ +// check-pass +// This is currently stable behavior, which was almost accidentally made an +// error in #102161 since there is no test exercising it. I am not sure if +// this _should_ be the desired behavior, but at least we should know if it +// changes. + +fn main() {} + +trait Foo { + fn fn_with_type_named_same_as_local_in_param(b: i32, b: i32); +} |
