about summary refs log tree commit diff
path: root/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs
blob: fd5edcc89eec0f4180fe11e8503c974d33866569 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//@ check-pass

// Regression test for #114572, We were inferring an ill-formed type:
//
// `Opaque<'a> = Static<&'a str>`, vs
// `Opaque<'a> = Static<&'static str>`.
//
// The hidden type of the opaque ends up as `Static<'?0 str>`. When
// computing member constraints we end up choosing `'a` for `?0` unless
// `?0` is already required to outlive `'a`. We achieve this by checking
// that `Static<'?0 str>` is well-formed.
#![feature(type_alias_impl_trait)]

struct Static<T: 'static>(T);

type OpaqueRet<'a> = impl Sized + 'a;
#[define_opaque(OpaqueRet)]
fn test_return<'a>(msg: Static<&'static u8>) -> OpaqueRet<'a> {
    msg
}

fn test_rpit<'a>(msg: Static<&'static u8>) -> impl Sized + 'a {
    msg
}

type OpaqueAssign<'a> = impl Sized + 'a;
#[define_opaque(OpaqueAssign)]
fn test_assign<'a>(msg: Static<&'static u8>) {
    let _: OpaqueAssign<'a> = msg;
}

// `OpaqueRef<'a, T> = Ref<'a, T>`, vs
// `OpaqueRef<'a, T> = Ref<'static, T>`.
trait RefAt<'a>: 'a {}
struct Ref<'a, T: RefAt<'a>>(&'a T);
type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a;
#[define_opaque(OpaqueRef)]
fn test_trait<'a, T: RefAt<'static>>(msg: Ref<'static, T>) -> OpaqueRef<'a, T> {
    msg
}

fn main() {}