|
| 1 | +// This is a non-regression test for issues #108721 and its duplicate #123275 (hopefully, because |
| 2 | +// the test is still convoluted and the ICE is fiddly). |
| 3 | +// |
| 4 | +// `pred_known_to_hold_modulo_regions` prevented "unexpected unsized tail" ICEs with warp/hyper but |
| 5 | +// was unknowingly removed in #120463. |
| 6 | + |
| 7 | +//@ build-pass: the ICE happened in codegen |
| 8 | + |
| 9 | +use std::future::Future; |
| 10 | +trait TryFuture: Future { |
| 11 | + type Ok; |
| 12 | +} |
| 13 | +impl<F, T> TryFuture for F |
| 14 | +where |
| 15 | + F: ?Sized + Future<Output = Option<T>>, |
| 16 | +{ |
| 17 | + type Ok = T; |
| 18 | +} |
| 19 | +trait Executor {} |
| 20 | +struct Exec {} |
| 21 | +trait HttpBody { |
| 22 | + type Data; |
| 23 | +} |
| 24 | +trait ConnStreamExec<F> {} |
| 25 | +impl<F> ConnStreamExec<F> for Exec where H2Stream<F>: Send {} |
| 26 | +impl<E, F> ConnStreamExec<F> for E where E: Executor {} |
| 27 | +struct H2Stream<F> { |
| 28 | + _fut: F, |
| 29 | +} |
| 30 | +trait NewSvcExec<S, E, W: Watcher<S, E>> { |
| 31 | + fn execute_new_svc(&mut self, _fut: NewSvcTask<S, E, W>) { |
| 32 | + unimplemented!() |
| 33 | + } |
| 34 | +} |
| 35 | +impl<S, E, W> NewSvcExec<S, E, W> for Exec where W: Watcher<S, E> {} |
| 36 | +trait Watcher<S, E> { |
| 37 | + type Future; |
| 38 | +} |
| 39 | +struct NoopWatcher; |
| 40 | +impl<S, E> Watcher<S, E> for NoopWatcher |
| 41 | +where |
| 42 | + S: HttpService, |
| 43 | + E: ConnStreamExec<S::Future>, |
| 44 | +{ |
| 45 | + type Future = Option<<<S as HttpService>::ResBody as HttpBody>::Data>; |
| 46 | +} |
| 47 | +trait Service<Request> { |
| 48 | + type Response; |
| 49 | + type Future; |
| 50 | +} |
| 51 | +trait HttpService { |
| 52 | + type ResBody: HttpBody; |
| 53 | + type Future; |
| 54 | +} |
| 55 | +struct Body {} |
| 56 | +impl HttpBody for Body { |
| 57 | + type Data = String; |
| 58 | +} |
| 59 | +impl<S> HttpService for S |
| 60 | +where |
| 61 | + S: Service<(), Response = ()>, |
| 62 | +{ |
| 63 | + type ResBody = Body; |
| 64 | + type Future = S::Future; |
| 65 | +} |
| 66 | +trait MakeServiceRef<Target> { |
| 67 | + type ResBody; |
| 68 | + type Service: HttpService<ResBody = Self::ResBody>; |
| 69 | +} |
| 70 | +impl<T, Target, S, F> MakeServiceRef<Target> for T |
| 71 | +where |
| 72 | + T: for<'a> Service<&'a Target, Response = S, Future = F>, |
| 73 | + S: HttpService, |
| 74 | +{ |
| 75 | + type Service = S; |
| 76 | + type ResBody = S::ResBody; |
| 77 | +} |
| 78 | +fn make_service_fn<F, Target, Ret>(_f: F) -> MakeServiceFn<F> |
| 79 | +where |
| 80 | + F: FnMut(&Target) -> Ret, |
| 81 | + Ret: Future, |
| 82 | +{ |
| 83 | + unimplemented!() |
| 84 | +} |
| 85 | +struct MakeServiceFn<F> { |
| 86 | + _func: F, |
| 87 | +} |
| 88 | +impl<'t, F, Ret, Target, Svc> Service<&'t Target> for MakeServiceFn<F> |
| 89 | +where |
| 90 | + F: FnMut(&Target) -> Ret, |
| 91 | + Ret: Future<Output = Option<Svc>>, |
| 92 | +{ |
| 93 | + type Response = Svc; |
| 94 | + type Future = Option<()>; |
| 95 | +} |
| 96 | +struct AddrIncoming {} |
| 97 | +struct Server<I, S, E> { |
| 98 | + _incoming: I, |
| 99 | + _make_service: S, |
| 100 | + _protocol: E, |
| 101 | +} |
| 102 | +impl<I, S, E, B> Server<I, S, E> |
| 103 | +where |
| 104 | + S: MakeServiceRef<(), ResBody = B>, |
| 105 | + B: HttpBody, |
| 106 | + E: ConnStreamExec<<S::Service as HttpService>::Future>, |
| 107 | + E: NewSvcExec<S::Service, E, NoopWatcher>, |
| 108 | +{ |
| 109 | + fn serve(&mut self) { |
| 110 | + let fut = NewSvcTask::new(); |
| 111 | + self._protocol.execute_new_svc(fut); |
| 112 | + } |
| 113 | +} |
| 114 | +fn serve<S>(_make_service: S) -> Server<AddrIncoming, S, Exec> { |
| 115 | + unimplemented!() |
| 116 | +} |
| 117 | +struct NewSvcTask<S, E, W: Watcher<S, E>> { |
| 118 | + _state: State<S, E, W>, |
| 119 | +} |
| 120 | +struct State<S, E, W: Watcher<S, E>> { |
| 121 | + _fut: W::Future, |
| 122 | +} |
| 123 | +impl<S, E, W: Watcher<S, E>> NewSvcTask<S, E, W> { |
| 124 | + fn new() -> Self { |
| 125 | + unimplemented!() |
| 126 | + } |
| 127 | +} |
| 128 | +trait Filter { |
| 129 | + type Extract; |
| 130 | + type Future; |
| 131 | + fn map<F>(self, _fun: F) -> MapFilter<Self, F> |
| 132 | + where |
| 133 | + Self: Sized, |
| 134 | + { |
| 135 | + unimplemented!() |
| 136 | + } |
| 137 | + fn wrap_with<W>(self, _wrapper: W) -> W::Wrapped |
| 138 | + where |
| 139 | + Self: Sized, |
| 140 | + W: Wrap<Self>, |
| 141 | + { |
| 142 | + unimplemented!() |
| 143 | + } |
| 144 | +} |
| 145 | +fn service<F>(_filter: F) -> FilteredService<F> |
| 146 | +where |
| 147 | + F: Filter, |
| 148 | +{ |
| 149 | + unimplemented!() |
| 150 | +} |
| 151 | +struct FilteredService<F> { |
| 152 | + _filter: F, |
| 153 | +} |
| 154 | +impl<F> Service<()> for FilteredService<F> |
| 155 | +where |
| 156 | + F: Filter, |
| 157 | +{ |
| 158 | + type Response = (); |
| 159 | + type Future = FilteredFuture<F::Future>; |
| 160 | +} |
| 161 | +struct FilteredFuture<F> { |
| 162 | + _fut: F, |
| 163 | +} |
| 164 | +struct MapFilter<T, F> { |
| 165 | + _filter: T, |
| 166 | + _func: F, |
| 167 | +} |
| 168 | +impl<T, F> Filter for MapFilter<T, F> |
| 169 | +where |
| 170 | + T: Filter, |
| 171 | + F: Func<T::Extract>, |
| 172 | +{ |
| 173 | + type Extract = F::Output; |
| 174 | + type Future = MapFilterFuture<T, F>; |
| 175 | +} |
| 176 | +struct MapFilterFuture<T: Filter, F> { |
| 177 | + _extract: T::Future, |
| 178 | + _func: F, |
| 179 | +} |
| 180 | +trait Wrap<F> { |
| 181 | + type Wrapped; |
| 182 | +} |
| 183 | +fn make_filter_fn<F, U>(_func: F) -> FilterFn<F> |
| 184 | +where |
| 185 | + F: Fn() -> U, |
| 186 | +{ |
| 187 | + unimplemented!() |
| 188 | +} |
| 189 | +struct FilterFn<F> { |
| 190 | + _func: F, |
| 191 | +} |
| 192 | +impl<F, U> Filter for FilterFn<F> |
| 193 | +where |
| 194 | + F: Fn() -> U, |
| 195 | + U: TryFuture, |
| 196 | + U::Ok: Send, |
| 197 | +{ |
| 198 | + type Extract = U::Ok; |
| 199 | + type Future = Option<U>; |
| 200 | +} |
| 201 | +fn trace<F>(_func: F) -> Trace<F> |
| 202 | +where |
| 203 | + F: Fn(), |
| 204 | +{ |
| 205 | + unimplemented!() |
| 206 | +} |
| 207 | +struct Trace<F> { |
| 208 | + _func: F, |
| 209 | +} |
| 210 | +impl<FN, F> Wrap<F> for Trace<FN> { |
| 211 | + type Wrapped = WithTrace<FN, F>; |
| 212 | +} |
| 213 | +struct WithTrace<FN, F> { |
| 214 | + _filter: F, |
| 215 | + _trace: FN, |
| 216 | +} |
| 217 | +impl<FN, F> Filter for WithTrace<FN, F> |
| 218 | +where |
| 219 | + F: Filter, |
| 220 | +{ |
| 221 | + type Extract = (); |
| 222 | + type Future = (F::Future, fn(F::Extract)); |
| 223 | +} |
| 224 | +trait Func<Args> { |
| 225 | + type Output; |
| 226 | +} |
| 227 | +impl<F, R> Func<()> for F |
| 228 | +where |
| 229 | + F: Fn() -> R, |
| 230 | +{ |
| 231 | + type Output = R; |
| 232 | +} |
| 233 | +fn main() { |
| 234 | + let make_service = make_service_fn(|_| { |
| 235 | + let tracer = trace(|| unimplemented!()); |
| 236 | + let filter = make_filter_fn(|| std::future::ready(Some(()))) |
| 237 | + .map(|| "Hello, world") |
| 238 | + .wrap_with(tracer); |
| 239 | + let svc = service(filter); |
| 240 | + std::future::ready(Some(svc)) |
| 241 | + }); |
| 242 | + let mut server = serve(make_service); |
| 243 | + server.serve(); |
| 244 | +} |
0 commit comments