Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make array patterns match on [T, ..n] and [T] only #478

Closed
ftxqxd opened this issue Nov 24, 2014 · 3 comments
Closed

Make array patterns match on [T, ..n] and [T] only #478

ftxqxd opened this issue Nov 24, 2014 · 3 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Nov 24, 2014

Array patterns currently match on either &[T] or [T, ..n]:

let x: &[int] = &[1, 2, 3];
let y: Box<[int]> = box [1, 2, 3];
let z: [int, ..3] = [1, 2, 3];

// Does not work
match x {
    &[1, 2, 3] => {},
    _ => {},
}

// Does not work
match y {
    box [1, 2, 3] => {},
    _ => {},
}

// Does work
match z {
    [1, 2, 3] => {},
    _ => {},
}

// Does work
match x {
    [1, 2, 3] => {},
    _ => {},
}

Logically, array patterns should only work on the bare array types, [T, ..n] and [T]. That would mean that all array patterns that match on &[T] would have to be prefixed by &, but it would also allow matching on Box<[T]> (and hypothetically, Rc<[T]>, Arc<[T]> etc. eventually). Has this already been considered (perhaps as part of DST)?

@brendanzab
Copy link
Member

+1. This is definitely confusing for some folks.

@Stebalien
Copy link
Contributor

Triage: Closed by #495?

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Feb 23, 2018
@Centril
Copy link
Contributor

Centril commented Feb 23, 2018

Yes, I think so - closing.

@Centril Centril closed this as completed Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants