summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/issue-61320-normalize.rs
blob: 095bef03f7cb9f9291d6693ec642e68fff2a0170 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Regression test for #61320
// This is the same issue as #61311, just a larger test case.

// check-pass

pub struct AndThen<A, B, F>
where
    A: Future,
    B: IntoFuture,
{
    state: (A, B::Future, F),
}

pub struct FutureResult<T, E> {
    inner: Option<Result<T, E>>,
}

impl<T, E> Future for FutureResult<T, E> {
    type Item = T;
    type Error = E;

    fn poll(&mut self) -> Poll<T, E> {
        unimplemented!()
    }
}

pub type Poll<T, E> = Result<T, E>;

impl<A, B, F> Future for AndThen<A, B, F>
where
    A: Future,
    B: IntoFuture<Error = A::Error>,
    F: FnOnce(A::Item) -> B,
{
    type Item = B::Item;
    type Error = B::Error;

    fn poll(&mut self) -> Poll<B::Item, B::Error> {
        unimplemented!()
    }
}

pub trait Future {
    type Item;

    type Error;

    fn poll(&mut self) -> Poll<Self::Item, Self::Error>;

    fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
    where
        F: FnOnce(Self::Item) -> B,
        B: IntoFuture<Error = Self::Error>,
        Self: Sized,
    {
        unimplemented!()
    }
}

pub trait IntoFuture {
    /// The future that this type can be converted into.
    type Future: Future<Item = Self::Item, Error = Self::Error>;

    /// The item that the future may resolve with.
    type Item;
    /// The error that the future may resolve with.
    type Error;

    /// Consumes this object and produces a future.
    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
    }
}

impl<F: ?Sized + Future> Future for ::std::boxed::Box<F> {
    type Item = F::Item;
    type Error = F::Error;

    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
        (**self).poll()
    }
}

impl<T, E> IntoFuture for Result<T, E> {
    type Future = FutureResult<T, E>;
    type Item = T;
    type Error = E;

    fn into_future(self) -> FutureResult<T, E> {
        unimplemented!()
    }
}

struct Request<T>(T);

trait RequestContext {}
impl<T> RequestContext for T {}
struct NoContext;
impl AsRef<NoContext> for NoContext {
    fn as_ref(&self) -> &Self {
        &NoContext
    }
}

type BoxedError = Box<dyn std::error::Error + Send + Sync>;
type DefaultFuture<T, E> = Box<dyn Future<Item = T, Error = E> + Send>;

trait Guard: Sized {
    type Result: IntoFuture<Item = Self, Error = BoxedError>;
    fn from_request(request: &Request<()>) -> Self::Result;
}

trait FromRequest: Sized {
    type Context;
    type Future: Future<Item = Self, Error = BoxedError> + Send;
    fn from_request(request: Request<()>) -> Self::Future;
}

struct MyGuard;
impl Guard for MyGuard {
    type Result = Result<Self, BoxedError>;
    fn from_request(_request: &Request<()>) -> Self::Result {
        Ok(MyGuard)
    }
}

struct Generic<I> {
    _inner: I,
}

impl<I> FromRequest for Generic<I>
where
    MyGuard: Guard,
    <MyGuard as Guard>::Result: IntoFuture<Item = MyGuard, Error = BoxedError>,
    <<MyGuard as Guard>::Result as IntoFuture>::Future: Send,
    I: FromRequest<Context = NoContext>,
{
    type Future = DefaultFuture<Self, BoxedError>;
    type Context = NoContext;
    fn from_request(headers: Request<()>) -> DefaultFuture<Self, BoxedError> {
        let _future = <MyGuard as Guard>::from_request(&headers)
            .into_future()
            .and_then(move |_| {
                <I as FromRequest>::from_request(headers)
                    .into_future()
                    .and_then(move |fld_inner| Ok(Generic { _inner: fld_inner }).into_future())
            });
        panic!();
    }
}

fn main() {}