From 60ac309d96f280726a5f69b2a34520077070c737 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 24 Feb 2023 22:30:41 -0700 Subject: [PATCH 1/3] 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); +} From 7d83d694b1e0c85fe21b6fac9c6d2c0b7fc0a409 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 24 Feb 2023 22:54:08 -0700 Subject: [PATCH 2/3] add `known-bug` test for unsoundness issue #107975 Part of the resolution to #105107 --- .../codegen/issue-107975-pointer-inequality.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/ui/codegen/issue-107975-pointer-inequality.rs diff --git a/tests/ui/codegen/issue-107975-pointer-inequality.rs b/tests/ui/codegen/issue-107975-pointer-inequality.rs new file mode 100644 index 0000000000000..b3c9d71a9bf70 --- /dev/null +++ b/tests/ui/codegen/issue-107975-pointer-inequality.rs @@ -0,0 +1,17 @@ +// run-pass +// known-bug: #107975 +fn main() { + let a: *const u8; + let b: *const u8; + { + let v: [u8; 16] = [core::hint::black_box(0); 16]; + a = &(v[0]); + } + { + let v: [u8; 16] = [core::hint::black_box(0); 16]; + b = &(v[0]); + } + assert_ne!(a, b); + println!("{a:?} {b:?}"); + assert_eq!(a, b); +} From 6adc76dff254534ad2712cd1dbf80ce6300c8c0c Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Fri, 24 Feb 2023 23:24:10 -0700 Subject: [PATCH 3/3] add `known-bug` test for unsoundness issue #105787 Part of the resolution to #105107 --- tests/ui/specialization/issue-105787.rs | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/ui/specialization/issue-105787.rs diff --git a/tests/ui/specialization/issue-105787.rs b/tests/ui/specialization/issue-105787.rs new file mode 100644 index 0000000000000..3cf655de2e5e1 --- /dev/null +++ b/tests/ui/specialization/issue-105787.rs @@ -0,0 +1,39 @@ +// check-pass +// known-bug: #105787 +trait ToUnit<'a> { + type Unit; +} + +struct LocalTy; +impl<'a> ToUnit<'a> for *const LocalTy { + type Unit = (); +} + +impl<'a, T: Copy + ?Sized> ToUnit<'a> for *const T { + type Unit = (); +} + +trait Overlap { + type Assoc; +} + +type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit; + +impl Overlap for T { + type Assoc = usize; +} + +impl Overlap fn(&'a (), Assoc<'a, T>)> for T +where + for<'a> *const T: ToUnit<'a>, +{ + type Assoc = Box; +} + +fn foo, U>(x: T::Assoc) -> T::Assoc { + x +} + +fn main() { + foo:: fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize); +}