Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
compiler-errors committed Oct 12, 2022
commit 1f2edd2146a1220bb8b602a1a21b189c70fae83c
5 changes: 4 additions & 1 deletion compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/impl-trait/unconstrained-tait-region-2.rs
Original file line number Diff line number Diff line change
@@ -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<Output = ()> + '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<Output = ()> + '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;
}
38 changes: 38 additions & 0 deletions src/test/ui/impl-trait/unconstrained-tait-region.rs
Original file line number Diff line number Diff line change
@@ -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: Fn()>(F);

impl<F: Fn()> Stream for ImplStream<F> {
type Item = Output;
}

impl Service for () {
type OutputStream = impl Stream<Item = Output>;

fn stream<'l, 'a>(&'l self) -> Self::OutputStream
where
Self: 'a,
'l: 'a,
{
ImplStream(|| ())
}
}

fn main() {}