Skip to content

Commit bfdd1c4

Browse files
committed
add known-bug test for unsound issue 40582
1 parent cb9aa8c commit bfdd1c4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
// known-bug: #40582
3+
4+
// Should fail. Should not be possible to implement `make_static`.
5+
6+
#![feature(specialization)]
7+
#![allow(incomplete_features)]
8+
9+
trait FromRef<'a, T: ?Sized> {
10+
fn from_ref(r: &'a T) -> Self;
11+
}
12+
13+
impl<'a, T: ?Sized> FromRef<'a, T> for &'a T {
14+
fn from_ref(r: &'a T) -> Self {
15+
r
16+
}
17+
}
18+
19+
impl<'a, T: ?Sized, R> FromRef<'a, T> for R {
20+
default fn from_ref(_: &'a T) -> Self {
21+
unimplemented!()
22+
}
23+
}
24+
25+
fn make_static<T: ?Sized>(data: &T) -> &'static T {
26+
fn helper<T: ?Sized, R>(data: &T) -> R {
27+
R::from_ref(data)
28+
}
29+
helper(data)
30+
}
31+
32+
fn main() {
33+
let s = "specialization".to_owned();
34+
println!("{:?}", make_static(s.as_str()));
35+
}

0 commit comments

Comments
 (0)