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.
Rollup merge of rust-lang#108445 - gburgessiv:add-known-bug, r=compil…
…er-errors Add known-bug tests for a few I-unsound issues Just a few commits to push rust-lang#105107 forward. r? ``@jackh726``
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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,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); | ||
} |
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,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<T> { | ||
type Assoc; | ||
} | ||
|
||
type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit; | ||
|
||
impl<T> Overlap<T> for T { | ||
type Assoc = usize; | ||
} | ||
|
||
impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T | ||
where | ||
for<'a> *const T: ToUnit<'a>, | ||
{ | ||
type Assoc = Box<usize>; | ||
} | ||
|
||
fn foo<T: Overlap<U>, U>(x: T::Assoc) -> T::Assoc { | ||
x | ||
} | ||
|
||
fn main() { | ||
foo::<for<'a> fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize); | ||
} |
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); | ||
} |