Skip to content

Commit c594330

Browse files
committed
add tests for unsound subtype handling
1 parent c911e08 commit c594330

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// run-pass
2+
// revisions: mir codegen
3+
//[mir] compile-flags: -Zmir-opt-level=3
4+
//[codegen] compile-flags: -Zmir-opt-level=0
5+
6+
// A regression test for #107205
7+
#![allow(coherence_leak_check)]
8+
struct Foo<T: 'static>(T);
9+
10+
fn useful<'a>(_: &'a u8) {}
11+
12+
trait GetInner {
13+
type Assoc;
14+
fn muahaha(&mut self) -> Self::Assoc;
15+
}
16+
17+
impl GetInner for Foo<fn(&'static u8)> {
18+
type Assoc = String;
19+
fn muahaha(&mut self) -> String {
20+
String::from("I am a string")
21+
}
22+
}
23+
24+
impl GetInner for Foo<for<'a> fn(&'a u8)> {
25+
type Assoc = [usize; 3];
26+
fn muahaha(&mut self) -> [usize; 3] {
27+
[100; 3]
28+
}
29+
}
30+
31+
fn break_me(hr_fnptr: Box<Foo::<for<'a> fn(&'a u8)>>) -> Box<dyn GetInner<Assoc = String>> {
32+
let lr_fnptr = hr_fnptr as Box<Foo<fn(&'static u8)>>;
33+
lr_fnptr as Box<dyn GetInner<Assoc = String>>
34+
}
35+
36+
fn main() {
37+
drop(Box::new(Foo(useful as fn(&'static u8))) as Box<dyn GetInner<Assoc = String>>);
38+
drop(Box::new(Foo(useful as fn(&u8))) as Box<dyn GetInner<Assoc = [usize; 3]>>);
39+
40+
let mut any = break_me(Box::new(Foo(useful)));
41+
42+
let evil_string = any.muahaha();
43+
assert_eq!(evil_string, "I am a string");
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-pass
2+
// revisions: mir codegen
3+
//[mir] compile-flags: -Zmir-opt-level=3
4+
//[codegen] compile-flags: -Zmir-opt-level=0
5+
6+
// A regression test for #107205
7+
8+
const X: for<'b> fn(&'b ()) = |&()| ();
9+
fn main() {
10+
let dyn_debug = Box::new(X) as Box<fn(&'static ())> as Box<dyn Send>;
11+
drop(dyn_debug)
12+
}

0 commit comments

Comments
 (0)