diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/traits/issue-38033.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/issue-38033.rs')
-rw-r--r-- | tests/ui/traits/issue-38033.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/ui/traits/issue-38033.rs b/tests/ui/traits/issue-38033.rs new file mode 100644 index 000000000..16b867ec8 --- /dev/null +++ b/tests/ui/traits/issue-38033.rs @@ -0,0 +1,79 @@ +// run-pass +use std::marker; +use std::mem; + +fn main() { + let workers = (0..0).map(|_| result::<u32, ()>()); + drop(join_all(workers).poll()); +} + +trait Future { + type Item; + type Error; + + fn poll(&mut self) -> Result<Self::Item, Self::Error>; +} + +trait IntoFuture { + type Future: Future<Item=Self::Item, Error=Self::Error>; + type Item; + type Error; + + fn into_future(self) -> Self::Future; +} + +impl<F: Future> IntoFuture for F { + type Future = F; + type Item = F::Item; + type Error = F::Error; + + fn into_future(self) -> F { + self + } +} + +struct FutureResult<T, E> { + _inner: marker::PhantomData<(T, E)>, +} + +fn result<T, E>() -> FutureResult<T, E> { + loop {} +} + +impl<T, E> Future for FutureResult<T, E> { + type Item = T; + type Error = E; + + fn poll(&mut self) -> Result<T, E> { + loop {} + } +} + +struct JoinAll<I> + where I: IntoIterator, + I::Item: IntoFuture, +{ + elems: Vec<<I::Item as IntoFuture>::Item>, +} + +fn join_all<I>(_: I) -> JoinAll<I> + where I: IntoIterator, + I::Item: IntoFuture, +{ + JoinAll { elems: vec![] } +} + +impl<I> Future for JoinAll<I> + where I: IntoIterator, + I::Item: IntoFuture, +{ + type Item = Vec<<I::Item as IntoFuture>::Item>; + type Error = <I::Item as IntoFuture>::Error; + + fn poll(&mut self) -> Result<Self::Item, Self::Error> { + let elems = mem::replace(&mut self.elems, Vec::new()); + Ok(elems.into_iter().map(|e| { + e + }).collect::<Vec<_>>()) + } +} |