Skip to content

Commit

Permalink
add known-bug test for unsoundness issue rust-lang#108425
Browse files Browse the repository at this point in the history
Part of the resolution to rust-lang#105107
  • Loading branch information
gburgessiv authored and GrigorenkoPV committed Jun 26, 2024
1 parent d7c5937 commit 2fc136b
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// known-bug: #108425
// check-pass
#![feature(type_alias_impl_trait)]
use std::fmt::Display;

type Opaque<'a> = impl Sized + 'static;
fn define<'a>() -> Opaque<'a> {}

trait Trait {
type Assoc: Display;
}
impl<'a> Trait for Opaque<'a> {
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<'_>>(&String::from("blah blah blah"));
println!("{}", val);
}

0 comments on commit 2fc136b

Please sign in to comment.