From 1f2edd2146a1220bb8b602a1a21b189c70fae83c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 12 Oct 2022 03:03:05 +0000 Subject: [PATCH] Properly support LUB for ReErased This is needed to properly check obligations on opaque types, since instead of returning ReEmpty, we now return ReErased for unconstrained regions in MIR borrowck. --- .../src/infer/lexical_region_resolve/mod.rs | 5 ++- .../impl-trait/unconstrained-tait-region-2.rs | 29 ++++++++++++++ .../impl-trait/unconstrained-tait-region.rs | 38 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/impl-trait/unconstrained-tait-region-2.rs create mode 100644 src/test/ui/impl-trait/unconstrained-tait-region.rs diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 5f13b2b3deb1b..5ac9dcc732c49 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -532,10 +532,13 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { #[instrument(level = "trace", skip(self), ret)] fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { match (*a, *b) { - (ReLateBound(..), _) | (_, ReLateBound(..)) | (ReErased, _) | (_, ReErased) => { + (ReLateBound(..), _) | (_, ReLateBound(..)) => { bug!("cannot relate region: LUB({:?}, {:?})", a, b); } + (_, ReErased) => a, + (ReErased, _) => b, + (ReVar(v_id), _) | (_, ReVar(v_id)) => { span_bug!( self.var_infos[v_id].origin.span(), diff --git a/src/test/ui/impl-trait/unconstrained-tait-region-2.rs b/src/test/ui/impl-trait/unconstrained-tait-region-2.rs new file mode 100644 index 0000000000000..326fe854cf2d7 --- /dev/null +++ b/src/test/ui/impl-trait/unconstrained-tait-region-2.rs @@ -0,0 +1,29 @@ +// check-pass +// edition:2021 + +#![feature(type_alias_impl_trait)] + +use std::future::Future; + +pub trait Ctx {} + +pub trait MyTrait { + type AssocT<'m, C>: Future + 'm + where + Self: 'm, + C: Ctx + 'm; + fn run<'d, C: Ctx + 'd>(&mut self, c: C) -> Self::AssocT<'_, C>; +} + +pub struct MyType; + +impl MyTrait for MyType { + type AssocT<'m, C> = impl Future + 'm where Self: 'm, C: Ctx + 'm; + fn run<'d, C: Ctx + 'd>(&mut self, c: C) -> Self::AssocT<'_, C> { + async move {} + } +} + +fn main() { + let t = MyType; +} diff --git a/src/test/ui/impl-trait/unconstrained-tait-region.rs b/src/test/ui/impl-trait/unconstrained-tait-region.rs new file mode 100644 index 0000000000000..207c9a16d2b32 --- /dev/null +++ b/src/test/ui/impl-trait/unconstrained-tait-region.rs @@ -0,0 +1,38 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +struct Output; + +trait Service { + type OutputStream; + + fn stream<'l, 'a>(&'l self) -> Self::OutputStream + where + Self: 'a, + 'l: 'a; +} + +trait Stream { + type Item; +} + +struct ImplStream(F); + +impl Stream for ImplStream { + type Item = Output; +} + +impl Service for () { + type OutputStream = impl Stream; + + fn stream<'l, 'a>(&'l self) -> Self::OutputStream + where + Self: 'a, + 'l: 'a, + { + ImplStream(|| ()) + } +} + +fn main() {}