Closed
Description
trait StaticDefaultRef: 'static {
fn default_ref() -> &'static Self;
}
impl StaticDefaultRef for str {
fn default_ref() -> &'static str {
""
}
}
fn into_impl(x: &str) -> &(impl ?Sized + AsRef<str> + StaticDefaultRef + '_) {
x
}
fn extend_lifetime<'a>(x: &'a str) -> &'static str {
let t = into_impl(x);
helper(|_| t)
}
fn helper<T: ?Sized + AsRef<str> + StaticDefaultRef>(f: impl FnOnce(&T) -> &T) -> &'static str {
f(T::default_ref()).as_ref()
}
fn main() {
let r;
{
let x = String::from("Hello World?");
r = extend_lifetime(&x);
}
println!("{}", r);
}
�j��0V�
So IMO the biggest problem in the code above is that the opaque type returned by into_impl
implements StaticDefaultRef
even though its lifetime is '_
, i.e. not 'static
.
This particular code only compiles since 1.45
, so this might be a regression.
@rustbot modify labels: T-compiler, A-impl-trait, A-lifetimes, A-typesystem
and someone please add “I-unsound 💥”.
Metadata
Metadata
Assignees
Labels
Area: Closures (`|…| { … }`)Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsArea: Type systemCategory: This is a bug.`#[feature(type_alias_impl_trait)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.
Type
Projects
Status
Done