-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Labels
T-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.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
[T; 0]
currently doesn't need drop glue by itself but still adds liveness requirements for T
when used in a more complex value which already needs drop.
This behavior is identitical to PhantomData
, which also does not need drop glue by itself but adds liveness requirements when used in values who do. I do not propose to change anything about PhantomData
with this issue.
Example
struct PrintOnDrop<'s>(&'s str);
impl<'s> Drop for PrintOnDrop<'s> {
fn drop(&mut self) {
println!("{}", self.0);
}
}
fn to_array_zero<T>(_: T) -> [T; 0] {
[]
}
pub fn array_zero_by_itself() {
let mut x = [];
{
let s = String::from("temporary");
let p = PrintOnDrop(&s);
x = to_array_zero(p)
}
// implicitly dropping `x` here, no drop glue needed,
// so ignoring outlives requirements. NO ERROR
}
pub fn array_zero_in_tuple() {
let mut x = ([], String::new());
{
let s = String::from("temporary");
let p = PrintOnDrop(&s);
x.0 = to_array_zero(p)
}
// implicitly dropping `x` here, drop glue needed to drop the `String`,
// adding outlives requirements for the zero array. ERROR
}
This behavior is confusing. I propose that we don't add any dropck outlives requirements for arrays of length zero. This allows strictly more code to compile, it may however result in unsoundness if people rely on this behavior to guarantee errors.
Rudxain
Metadata
Metadata
Assignees
Labels
T-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.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.