Skip to content

Diagnostics for @ .. idiom use in tuple and tuple struct patterns is incorrect #72574

Closed
@chrissimpkins

Description

@chrissimpkins

@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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions