-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Description
Simple demo https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5b0acd8b21c773c9c4a3ff73bc7a030e:
#![allow(unused_variables)]
struct Zeroes;
impl Into<[usize; 2]> for Zeroes {
fn into(self) -> [usize; 2] { [0; 2] }
}
impl Into<[usize; 3]> for Zeroes {
fn into(self) -> [usize; 3] { [0; 3] }
}
impl Into<[usize; 4]> for Zeroes {
fn into(self) -> [usize; 4] { [0; 4] }
}
fn main() {
let [a, b, c] = Zeroes.into(); // ERROR: type annotations needed
let [d, e, f]: [_; 3] = Zeroes.into(); // Works great
}
This is presumably not happening because slice patterns in refutable patterns can be more than just an array of that exact size, but there's no other option for irrefutable patterns.
This would be particularly helpful as we're getting more and more [T; N]: TryFrom<_>
implementations with const generics. See the example in #76310 for the place I first noticed this not working the way I'd hoped.
workingjubilee and pickfire
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.