-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.NLL-soundWorking towards the "invalid code does not compile" goalWorking towards the "invalid code does not compile" goalT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.NLL-soundWorking towards the "invalid code does not compile" goalWorking towards the "invalid code does not compile" goalT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Activity
Auto merge of rust-lang#104098 - aliemjay:fn-wf, r=<try>
Auto merge of rust-lang#120019 - lcnr:fn-wf, r=BoxyUwU