about summary refs log tree commit diff
path: root/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs
blob: 415021a1808c211a41b084e5e991431268b1ef12 (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
#![feature(type_alias_impl_trait)]

use std::fmt::Display;

type Opaque<X> = impl Sized + 'static;
#[define_opaque(Opaque)]
fn define<X>() -> Opaque<X> {}

trait Trait {
    type Assoc: Display;
}
impl<'a> Trait for Opaque<&'a str> {
    //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
    type Assoc = &'a str;
}

// ======= Exploit =======

fn extend<T: Trait + 'static>(s: T::Assoc) -> Box<dyn Display> {
    Box::new(s)
}

fn main() {
    let val = extend::<Opaque<&'_ str>>(&String::from("blah blah blah"));
    println!("{}", val);
}