Skip to content

Commit 1f2edd2

Browse files
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.
1 parent db0597f commit 1f2edd2

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,13 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
532532
#[instrument(level = "trace", skip(self), ret)]
533533
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
534534
match (*a, *b) {
535-
(ReLateBound(..), _) | (_, ReLateBound(..)) | (ReErased, _) | (_, ReErased) => {
535+
(ReLateBound(..), _) | (_, ReLateBound(..)) => {
536536
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
537537
}
538538

539+
(_, ReErased) => a,
540+
(ReErased, _) => b,
541+
539542
(ReVar(v_id), _) | (_, ReVar(v_id)) => {
540543
span_bug!(
541544
self.var_infos[v_id].origin.span(),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![feature(type_alias_impl_trait)]
5+
6+
use std::future::Future;
7+
8+
pub trait Ctx {}
9+
10+
pub trait MyTrait {
11+
type AssocT<'m, C>: Future<Output = ()> + 'm
12+
where
13+
Self: 'm,
14+
C: Ctx + 'm;
15+
fn run<'d, C: Ctx + 'd>(&mut self, c: C) -> Self::AssocT<'_, C>;
16+
}
17+
18+
pub struct MyType;
19+
20+
impl MyTrait for MyType {
21+
type AssocT<'m, C> = impl Future<Output = ()> + 'm where Self: 'm, C: Ctx + 'm;
22+
fn run<'d, C: Ctx + 'd>(&mut self, c: C) -> Self::AssocT<'_, C> {
23+
async move {}
24+
}
25+
}
26+
27+
fn main() {
28+
let t = MyType;
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
struct Output;
6+
7+
trait Service {
8+
type OutputStream;
9+
10+
fn stream<'l, 'a>(&'l self) -> Self::OutputStream
11+
where
12+
Self: 'a,
13+
'l: 'a;
14+
}
15+
16+
trait Stream {
17+
type Item;
18+
}
19+
20+
struct ImplStream<F: Fn()>(F);
21+
22+
impl<F: Fn()> Stream for ImplStream<F> {
23+
type Item = Output;
24+
}
25+
26+
impl Service for () {
27+
type OutputStream = impl Stream<Item = Output>;
28+
29+
fn stream<'l, 'a>(&'l self) -> Self::OutputStream
30+
where
31+
Self: 'a,
32+
'l: 'a,
33+
{
34+
ImplStream(|| ())
35+
}
36+
}
37+
38+
fn main() {}

0 commit comments

Comments
 (0)