]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-61320-normalize.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[rust.git] / src / test / ui / nll / issue-61320-normalize.rs
1 // Regression test for #61320
2 // This is the same issue as #61311, just a larger test case.
3
4 // check-pass
5
6 pub struct AndThen<A, B, F>
7 where
8     A: Future,
9     B: IntoFuture,
10 {
11     state: (A, B::Future, F),
12 }
13
14 pub struct FutureResult<T, E> {
15     inner: Option<Result<T, E>>,
16 }
17
18 impl<T, E> Future for FutureResult<T, E> {
19     type Item = T;
20     type Error = E;
21
22     fn poll(&mut self) -> Poll<T, E> {
23         unimplemented!()
24     }
25 }
26
27 pub type Poll<T, E> = Result<T, E>;
28
29 impl<A, B, F> Future for AndThen<A, B, F>
30 where
31     A: Future,
32     B: IntoFuture<Error = A::Error>,
33     F: FnOnce(A::Item) -> B,
34 {
35     type Item = B::Item;
36     type Error = B::Error;
37
38     fn poll(&mut self) -> Poll<B::Item, B::Error> {
39         unimplemented!()
40     }
41 }
42
43 pub trait Future {
44     type Item;
45
46     type Error;
47
48     fn poll(&mut self) -> Poll<Self::Item, Self::Error>;
49
50     fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
51     where
52         F: FnOnce(Self::Item) -> B,
53         B: IntoFuture<Error = Self::Error>,
54         Self: Sized,
55     {
56         unimplemented!()
57     }
58 }
59
60 pub trait IntoFuture {
61     /// The future that this type can be converted into.
62     type Future: Future<Item = Self::Item, Error = Self::Error>;
63
64     /// The item that the future may resolve with.
65     type Item;
66     /// The error that the future may resolve with.
67     type Error;
68
69     /// Consumes this object and produces a future.
70     fn into_future(self) -> Self::Future;
71 }
72
73 impl<F: Future> IntoFuture for F {
74     type Future = F;
75     type Item = F::Item;
76     type Error = F::Error;
77
78     fn into_future(self) -> F {
79         self
80     }
81 }
82
83 impl<F: ?Sized + Future> Future for ::std::boxed::Box<F> {
84     type Item = F::Item;
85     type Error = F::Error;
86
87     fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
88         (**self).poll()
89     }
90 }
91
92 impl<T, E> IntoFuture for Result<T, E> {
93     type Future = FutureResult<T, E>;
94     type Item = T;
95     type Error = E;
96
97     fn into_future(self) -> FutureResult<T, E> {
98         unimplemented!()
99     }
100 }
101
102 struct Request<T>(T);
103
104 trait RequestContext {}
105 impl<T> RequestContext for T {}
106 struct NoContext;
107 impl AsRef<NoContext> for NoContext {
108     fn as_ref(&self) -> &Self {
109         &NoContext
110     }
111 }
112
113 type BoxedError = Box<dyn std::error::Error + Send + Sync>;
114 type DefaultFuture<T, E> = Box<dyn Future<Item = T, Error = E> + Send>;
115
116 trait Guard: Sized {
117     type Result: IntoFuture<Item = Self, Error = BoxedError>;
118     fn from_request(request: &Request<()>) -> Self::Result;
119 }
120
121 trait FromRequest: Sized {
122     type Context;
123     type Future: Future<Item = Self, Error = BoxedError> + Send;
124     fn from_request(request: Request<()>) -> Self::Future;
125 }
126
127 struct MyGuard;
128 impl Guard for MyGuard {
129     type Result = Result<Self, BoxedError>;
130     fn from_request(_request: &Request<()>) -> Self::Result {
131         Ok(MyGuard)
132     }
133 }
134
135 struct Generic<I> {
136     _inner: I,
137 }
138
139 impl<I> FromRequest for Generic<I>
140 where
141     MyGuard: Guard,
142     <MyGuard as Guard>::Result: IntoFuture<Item = MyGuard, Error = BoxedError>,
143     <<MyGuard as Guard>::Result as IntoFuture>::Future: Send,
144     I: FromRequest<Context = NoContext>,
145 {
146     type Future = DefaultFuture<Self, BoxedError>;
147     type Context = NoContext;
148     fn from_request(headers: Request<()>) -> DefaultFuture<Self, BoxedError> {
149         let _future = <MyGuard as Guard>::from_request(&headers)
150             .into_future()
151             .and_then(move |_| {
152                 <I as FromRequest>::from_request(headers)
153                     .into_future()
154                     .and_then(move |fld_inner| Ok(Generic { _inner: fld_inner }).into_future())
155             });
156         panic!();
157     }
158 }
159
160 fn main() {}