Open
Description
I see this briefly mentioned in #31844 but no existing issue tracking the incorrect behavior.
Something in the following code is unsound. It should not be possible to implement make_static
.
#![feature(specialization)]
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 main() {
let s = "specialization".to_owned();
println!("{:?}", make_static(s.as_str()));
}
fn make_static<T: ?Sized>(data: &T) -> &'static T {
fn helper<T: ?Sized, R>(data: &T) -> R {
R::from_ref(data)
}
helper(data)
}
Metadata
Metadata
Assignees
Labels
Area: Trait impl specializationBlocker: Implemented in the nightly compiler and unstable.Category: This is a bug.`#![feature(specialization)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessMedium priorityStatus: This bug is tracked inside the repo by a `known-bug` test.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.