Closed
Description
#![feature(const_trait_impl)]
fn extend_lifetime(x: &str) -> &'static str {
f::<S>(x)
}
const fn f<'a, T: Tr<'a> + ~const Drop>(x: &'a str) -> T::Ty {
// can call g with T: Drop bound, even though
// T: ~const Drop works for non-Drop-implementing types
g::<T>(x)
}
#[allow(drop_bounds)]
const fn g<T: Drop>(x: &str) -> <T as Tr<'_>>::Ty {
x
}
struct S;
trait Tr<'a> {
type Ty;
}
#[allow(drop_bounds)]
impl<'a, T: Drop> Tr<'a> for T {
type Ty = &'a str;
}
impl<'a> Tr<'a> for S {
type Ty = &'static str;
}
fn main() {
let x = "Hello World".to_owned();
let s = extend_lifetime(&x);
drop(x);
println!("{s}");
}
��)
@rustbot label requires-nightly, I-unsound, T-compiler, F-const_trait_impl, A-const-fn
By the way, even if this worked “correctly” (i.e. soundly) I really hate the fact that this feature is using a sort of T: Drop
bound; the drop_bounds
warning exists for a reason, using the Drop
trait in bounds is discouraged for a reason, abusing it as in the feature that allows “T: ~const Drop
” makes everything just sooo much more confusing and inconsistent.
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Category: This is a bug.`#![feature(const_trait_impl)]`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.