-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-arrayArea: `[T; N]`Area: `[T; N]`A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.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.
Description
I tried this code:
use std::marker::PhantomData;
pub struct Thing<'a> {
_phantom: PhantomData<fn(&'a ()) -> &'a ()>,
}
pub fn foo<'a, 'b>(x: Thing<'a>) -> [Thing<'b>; 0] {
[x; 0]
}
pub fn lol<'a, 'b>(x: &'a i32) -> [&'b i32; 0] {
[x; 0]
}
I expected the code not to compile, but instead it compiles without errors or warnings.
See also #79580, which is about [expr; 0]
being weird.
Meta
Reproducible on the playground with 1.90.0-nightly (2025-07-15 3014e79f9c8d5510ea7b)
@rustbot labels +A-zst +A-lifetimes
Metadata
Metadata
Assignees
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-arrayArea: `[T; N]`Area: `[T; N]`A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.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.