Unsoundness due to where clauses not checked for well-formedness · Issue #98117 · rust-lang/rust (original) (raw)
This code does pass: (playground)
trait Outlives<'a>: 'a {} // without : 'a
, it fails as expected.
fn t_is_static() 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) -> &'static str where &'static T: Outlives<'static>, T: AsRef, { AsRef::as_ref(Box::leak(Box::new(t) as Box<dyn AsRef + 'static>)) }
fn step1(t: T) -> &'static str where for<'a> &'a T: Outlives<'a>, T: AsRef, { 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