-
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-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Consider this code:
use std::marker::PhantomData;
struct Pending<T> {
phantom: PhantomData<T>,
}
fn pending<T>(value: T) -> Pending<T> {
Pending {
phantom: PhantomData,
}
}
struct Inspector<'a> {
value: &'a String,
}
impl Drop for Inspector<'_> {
fn drop(&mut self) {
eprintln!("drop inspector {}", self.value)
}
}
fn main() {
let p: Pending<Inspector>;
let s = "hello".to_string();
p = pending(Inspector { value: &s });
}
I believe it should not compile (by failing dropcheck). It, however, compiles and runs on 1.42 and 1.31. On 1.24 it indeed fails as I expect.
The equivalent code, where PhantomData<T>
is replaced with T
rightfully fails to compiles: Playground. So, dropchk somehow observes the difference between T
and PhantomData<T>
?
Either I misunderstand how PhantomData<T>
is supposed to work, or this is a stable-to-stable regression and a soundless hole.
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.