Closed
Description
The following should fail: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=55b6d108fe6712536a9c7a7abea56bc0
trait Trait {
const TRAIT: bool;
}
impl<T> Trait for &'static T {
const TRAIT: bool = true;
}
fn test<T>() {
<&'static T>::TRAIT;
}
It should require a T: 'static
bound on test
.
This is unsound but can't currently be exploited because of #98852. A potential exploit would be like:
trait Trait<'a> {
const TRAIT: fn(&'a str) -> &'static str;
}
impl<'a> Trait<'a> for &'static &'a () { // implies 'a: 'static
const TRAIT: fn(&'a str) -> &'static str = {
|x| x // this should pass if we use implied bounds from impl header
};
}
fn test<T>() {
let val = <&'static &'_ ()>::TRAIT(&String::new()); // we should error here!
println!("{}", val);
}
@rustbot label T-types C-bug A-NLL NLL-sound A-borrow-checker
@rustbot claim