Closed
Description
#![feature(min_type_alias_impl_trait)]
use std::marker::PhantomData;
trait ProofForConversion<'a, 'b> {
fn convert<T: ?Sized>(_: PhantomData<Self>, r: &'a T) -> &'b T;
}
impl<'a, 'b> ProofForConversion<'a, 'b> for &'b &'a () {
fn convert<T: ?Sized>(_: PhantomData<Self>, r: &'a T) -> &'b T {
r
}
}
type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>;
// Even _defining_use with an explicit `'a: 'b` compiles fine, too.
fn _defining_use<'a, 'b>(x: &'b &'a ()) -> Converter<'a, 'b> {
x
}
fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
Converter::<'a, 'b>::convert(PhantomData, x)
}
fn main() {
let d;
{
let x = "Hello World".to_string();
d = extend_lifetime(&x);
}
println!("{}", d);
}
��C
I would’ve expected rustc to complain about the _defining_use
not matching the type Converter<'a, 'b>
with a suggestion to turn it into type Converter<'a: 'b, 'a>
.
@rustbot modify labels: A-typesystem, A-lifetimes, A-traits, A-impl-trait, F-type_alias_impl_trait, T-compiler, requires-nightly
and someone please add “I-unsound 💥” (and/or tell me if there is a way to do it myself).
Metadata
Metadata
Assignees
Labels
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsArea: Trait systemArea: 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/SoundnessRelevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.
Type
Projects
Status
Done