]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hrtb/issue-95034.rs
Auto merge of #98120 - TaKO8Ki:box-diagnostic-metadata-field, r=estebank
[rust.git] / src / test / ui / hrtb / issue-95034.rs
1 // known-bug: #95034
2 // failure-status: 101
3 // compile-flags: --edition=2021 --crate-type=lib
4 // rustc-env:RUST_BACKTRACE=0
5
6 // normalize-stderr-test "thread 'rustc' panicked.*" -> "thread 'rustc' panicked"
7 // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
8 // normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> ""
9 // normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> ""
10 // normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
11 // normalize-stderr-test "note: compiler flags.*\n\n" -> ""
12 // normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
13 // normalize-stderr-test "query stack during panic:\n" -> ""
14 // normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
15 // normalize-stderr-test "end of query stack\n" -> ""
16 // normalize-stderr-test "#.*\n" -> ""
17
18 // This should not ICE.
19
20 // Refer to the issue for more minimized versions.
21
22 use std::{
23     future::Future,
24     marker::PhantomData,
25     pin::Pin,
26     task::{Context, Poll},
27 };
28
29 mod object {
30     use super::*;
31
32     pub trait Object<'a> {
33         type Error;
34         type Future: Future<Output = Self>;
35         fn create() -> Self::Future;
36     }
37
38     impl<'a> Object<'a> for u8 {
39         type Error = ();
40         type Future = Pin<Box<dyn Future<Output = Self>>>;
41         fn create() -> Self::Future {
42             unimplemented!()
43         }
44     }
45
46     impl<'a, E, A: Object<'a, Error = E>> Object<'a> for (A,) {
47         type Error = ();
48         type Future = CustomFut<'a, E, A>;
49         fn create() -> Self::Future {
50             unimplemented!()
51         }
52     }
53
54     pub struct CustomFut<'f, E, A: Object<'f, Error = E>> {
55         ph: PhantomData<(A::Future,)>,
56     }
57
58     impl<'f, E, A: Object<'f, Error = E>> Future for CustomFut<'f, E, A> {
59         type Output = (A,);
60         fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
61             unimplemented!()
62         }
63     }
64 }
65
66 mod async_fn {
67     use super::*;
68
69     pub trait AsyncFn {
70         type Future: Future<Output = ()>;
71         fn call(&self) -> Self::Future;
72     }
73
74     impl<F, Fut> AsyncFn for F
75     where
76         F: Fn() -> Fut,
77         Fut: Future<Output = ()>,
78     {
79         type Future = Fut;
80         fn call(&self) -> Self::Future {
81             (self)()
82         }
83     }
84 }
85
86 pub async fn test() {
87     use self::{async_fn::AsyncFn, object::Object};
88
89     async fn create<T: Object<'static>>() {
90         T::create().await;
91     }
92
93     async fn call_async_fn(inner: impl AsyncFn) {
94         inner.call().await;
95     }
96
97     call_async_fn(create::<(u8,)>).await;
98 }