From 2953a2fb18ccc5a61aae79cd62a8383f3456c1db Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 26 Jul 2021 14:59:26 +0000 Subject: [PATCH] Mir borrowck does not generate lifetime variables for 'static lifetimes during opaque type resolution --- .../borrow_check/region_infer/opaque_types.rs | 1 + .../issue-87455-static-lifetime-ice.rs | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/issue-87455-static-lifetime-ice.rs diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs index f2d69255d50..e9ab62e1664 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs +++ b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs @@ -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 index 00000000000..80a74eb63a8 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-87455-static-lifetime-ice.rs @@ -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>; + fn size_hint(&self) -> (usize, Option) { + (0, None) + } +} + +pub trait TryStream: Stream { + type Ok; + type Error; + + fn try_poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>>; +} + +impl TryStream for S +where + S: ?Sized + Stream>, +{ + type Ok = T; + type Error = E; + + fn try_poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>> { + self.poll_next(cx) + } +} + +pub trait ServerSentEvent: Sized + Send + Sync + 'static {} + +impl ServerSentEvent for T {} + +struct SseKeepAlive { + event_stream: S, +} + +struct SseComment(T); + +impl Stream for SseKeepAlive +where + S: TryStream + Send + 'static, + S::Ok: ServerSentEvent, + S::Error: StdError + Send + Sync + 'static, +{ + type Item = Result, ()>; + fn poll_next(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { + unimplemented!() + } +} + +pub fn keep( + event_stream: S, +) -> impl TryStream + Send + 'static +where + S: TryStream + Send + 'static, + S::Ok: ServerSentEvent + Send, + S::Error: StdError + Send + Sync + 'static, +{ + SseKeepAlive { event_stream } +} + +fn main() {} -- 2.44.0