mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
add known-bug test for unsound issue 40582
This commit is contained in:
parent
cb9aa8c9c1
commit
bfdd1c4e35
35
tests/ui/specialization/issue-40582.rs
Normal file
35
tests/ui/specialization/issue-40582.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// check-pass
|
||||
// known-bug: #40582
|
||||
|
||||
// Should fail. Should not be possible to implement `make_static`.
|
||||
|
||||
#![feature(specialization)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait FromRef<'a, T: ?Sized> {
|
||||
fn from_ref(r: &'a T) -> Self;
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> FromRef<'a, T> for &'a T {
|
||||
fn from_ref(r: &'a T) -> Self {
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized, R> FromRef<'a, T> for R {
|
||||
default fn from_ref(_: &'a T) -> Self {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn make_static<T: ?Sized>(data: &T) -> &'static T {
|
||||
fn helper<T: ?Sized, R>(data: &T) -> R {
|
||||
R::from_ref(data)
|
||||
}
|
||||
helper(data)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = "specialization".to_owned();
|
||||
println!("{:?}", make_static(s.as_str()));
|
||||
}
|
Loading…
Reference in New Issue
Block a user