]> git.lizzy.rs Git - rust.git/commitdiff
Mir borrowck does not generate lifetime variables for 'static lifetimes during opaque...
authorOli Scherer <github35764891676564198441@oli-obk.de>
Mon, 26 Jul 2021 14:59:26 +0000 (14:59 +0000)
committerOli Scherer <github35764891676564198441@oli-obk.de>
Mon, 26 Jul 2021 16:35:32 +0000 (16:35 +0000)
compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
src/test/ui/type-alias-impl-trait/issue-87455-static-lifetime-ice.rs [new file with mode: 0644]

index f2d69255d50ffb0f64a77f52b566c280c3bdcfb1..e9ab62e1664f972778fa884a8b46a9f53f6f62cd 100644 (file)
@@ -83,6 +83,7 @@ pub(in crate::borrow_check) fn infer_opaque_types(
                             .and_then(|ur_vid| self.definitions[*ur_vid].external_name)
                             .unwrap_or(infcx.tcx.lifetimes.re_root_empty),
                         ty::ReLateBound(..) => region,
+                        ty::ReStatic => region,
                         _ => {
                             infcx.tcx.sess.delay_span_bug(
                                 span,
diff --git a/src/test/ui/type-alias-impl-trait/issue-87455-static-lifetime-ice.rs b/src/test/ui/type-alias-impl-trait/issue-87455-static-lifetime-ice.rs
new file mode 100644 (file)
index 0000000..80a74eb
--- /dev/null
@@ -0,0 +1,73 @@
+// check-pass
+
+use std::error::Error as StdError;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+pub trait Stream {
+    type Item;
+    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        (0, None)
+    }
+}
+
+pub trait TryStream: Stream {
+    type Ok;
+    type Error;
+
+    fn try_poll_next(
+        self: Pin<&mut Self>,
+        cx: &mut Context<'_>,
+    ) -> Poll<Option<Result<Self::Ok, Self::Error>>>;
+}
+
+impl<S, T, E> TryStream for S
+where
+    S: ?Sized + Stream<Item = Result<T, E>>,
+{
+    type Ok = T;
+    type Error = E;
+
+    fn try_poll_next(
+        self: Pin<&mut Self>,
+        cx: &mut Context<'_>,
+    ) -> Poll<Option<Result<Self::Ok, Self::Error>>> {
+        self.poll_next(cx)
+    }
+}
+
+pub trait ServerSentEvent: Sized + Send + Sync + 'static {}
+
+impl<T: Send + Sync + 'static> ServerSentEvent for T {}
+
+struct SseKeepAlive<S> {
+    event_stream: S,
+}
+
+struct SseComment<T>(T);
+
+impl<S> Stream for SseKeepAlive<S>
+where
+    S: TryStream + Send + 'static,
+    S::Ok: ServerSentEvent,
+    S::Error: StdError + Send + Sync + 'static,
+{
+    type Item = Result<SseComment<&'static str>, ()>;
+    fn poll_next(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Option<Self::Item>> {
+        unimplemented!()
+    }
+}
+
+pub fn keep<S>(
+    event_stream: S,
+) -> impl TryStream<Ok = impl ServerSentEvent + Send + 'static, Error = ()> + Send + 'static
+where
+    S: TryStream + Send + 'static,
+    S::Ok: ServerSentEvent + Send,
+    S::Error: StdError + Send + Sync + 'static,
+{
+    SseKeepAlive { event_stream }
+}
+
+fn main() {}