forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
known-bug
test for unsoundness issue rust-lang#108425
Part of the resolution to rust-lang#105107
- Loading branch information
1 parent
d7c5937
commit 2fc136b
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
tests/ui/type-alias-impl-trait/issue-108425-impl-generics-unsoundness.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |