From 2fc136b81eb841eef546f70981d3164414de9b85 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 24 Feb 2023 22:30:41 -0700 Subject: [PATCH] add `known-bug` test for unsoundness issue #108425 Part of the resolution to #105107 --- .../issue-108425-impl-generics-unsoundness.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/type-alias-impl-trait/issue-108425-impl-generics-unsoundness.rs diff --git a/tests/ui/type-alias-impl-trait/issue-108425-impl-generics-unsoundness.rs b/tests/ui/type-alias-impl-trait/issue-108425-impl-generics-unsoundness.rs new file mode 100644 index 0000000000000..b0dbc0a014b77 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-108425-impl-generics-unsoundness.rs @@ -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(s: T::Assoc) -> Box { + Box::new(s) +} + +fn main() { + let val = extend::>(&String::from("blah blah blah")); + println!("{}", val); +}