Closed
Description
This code does pass: (playground)
trait Outlives<'a>: 'a {} // without `: 'a`, it fails as expected.
fn t_is_static<T>()
where
&'static T: Outlives<'static>,
{
}
But according to RFC 1214 functions are responsible for checking the well-formedness of their own where clauses. So this should fail and require an explicit bound T: 'static
.
Here is an exploit of this unsoundness: (playground)
trait Outlives<'a>: 'a {}
impl<'a, T> Outlives<'a> for &'a T {}
fn step2<T>(t: T) -> &'static str
where
&'static T: Outlives<'static>,
T: AsRef<str>,
{
AsRef::as_ref(Box::leak(Box::new(t) as Box<dyn AsRef<str> + 'static>))
}
fn step1<T>(t: T) -> &'static str
where
for<'a> &'a T: Outlives<'a>,
T: AsRef<str>,
{
step2(t)
}
fn main() {
let s: &'static str = step1(&String::from("blah blah blah"));
println!("{s}");
}
@rustbot label C-bug T-compiler T-types A-lifetimes I-unsound
Metadata
Metadata
Assignees
Labels
Area: Lifetimes / regionsCategory: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh 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.