summaryrefslogtreecommitdiffstats
path: root/tests/ui/impl-trait/issue-103181-1.rs
blob: 5154abcd690704dd103ea6904e3100f588e2dc60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next
// edition:2021

mod hyper {
    use std::{fmt::Debug, future::Future, marker::PhantomData, pin::Pin, task::Poll};

    pub trait HttpBody {
        type Error;
    }
    impl HttpBody for () {
        //~^ ERROR not all trait items implemented, missing: `Error`
        // don't implement `Error` here for the ICE
    }

    pub struct Server<I, S>(I, S);

    pub fn serve<I, S>(_: S) -> Server<I, S> {
        todo!()
    }

    impl<S, B> Future for Server<(), S>
    where
        S: MakeServiceRef<(), (), ResBody = B>,
        B: HttpBody,
        B::Error: Debug,
    {
        type Output = ();

        fn poll(self: Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> {
            todo!()
        }
    }

    pub trait MakeServiceRef<Target, ReqBody> {
        type ResBody;
    }

    impl<T, S> MakeServiceRef<(), ()> for T
    where
        T: for<'a> Service<&'a (), Response = S>,
        S: Service<()>,
    {
        type ResBody = ();
    }

    pub struct MakeServiceFn<F>(pub F);
    pub struct ServiceFn<F, R>(pub PhantomData<(F, R)>);

    pub trait Service<Request> {
        type Response;
    }

    impl<'t, F, Ret, Target, Svc> Service<&'t Target> for MakeServiceFn<F>
    where
        F: Fn() -> Ret,
        Ret: Future<Output = Result<Svc, ()>>,
    {
        type Response = Svc;
    }

    impl<F, ReqBody, Ret, ResBody, E> Service<ReqBody> for ServiceFn<F, ReqBody>
    where
        F: Fn() -> Ret,
        Ret: Future<Output = Result<ResBody, E>>,
    {
        type Response = ResBody;
    }
}

async fn smarvice() -> Result<(), ()> {
    Ok(())
}

fn service_fn<F, R, S>(f: F) -> hyper::ServiceFn<F, R>
where
    F: Fn() -> S,
{
    hyper::ServiceFn(std::marker::PhantomData)
}

async fn iceice() {
    let service = hyper::MakeServiceFn(|| async { Ok::<_, ()>(service_fn(|| smarvice())) });
    hyper::serve::<(), _>(service).await;
}

fn main() {}