Closed
Description
@estebank and I are working on diagnostics for the @ ..
rest idiom in slice patterns (#72534) and came across this issue when an attempt is made to use it in tuples and tuple structs.
IIUC, this is allowed:
tuple (playground)
fn main() {
let x = (1, 2, 3);
match x {
(_a, ..) => {}
_ => {}
}
}
tuple struct (playground)
struct Binder(i32, i32, i32);
fn main() {
let x = Binder(1, 2, 3);
match x {
Binder(_a, ..) => {}
_ => {}
}
}
and this is not allowed (note the addition of [id] @
):
tuple (playground)
fn main() {
let x = (1, 2, 3);
match x {
(_a, _x @ ..) => {}
_ => {}
}
}
tuple struct (playground)
struct Binder(i32, i32, i32);
fn main() {
let x = Binder(1, 2, 3);
match x {
Binder(_a, _x @ ..) => {}
_ => {}
}
}
The error messages for the tuple and tuple struct cases include the following incorrect information:
error:
..
patterns are not allowed here
This should state that the @ ..
id binding to rest is not allowed. ..
patterns are allowed.
note: only allowed in tuple, tuple struct, and slice patterns
@ ..
is only allowed in slice patterns, not in tuple or tuple struct patterns. This should state that the idiom is only allowed in slice patterns.