Skip to content

Comma not allowed after last field in struct destructuring #10392

Closed
@brendanzab

Description

@brendanzab
struct A {
    long_field_name_1: int,
    long_field_name_2: int,
}

static a: A = A {
    long_field_name_1: 1,
    long_field_name_2: 2,
};

// trailing-comma.rs:16:8: 16:9 error: expected ident, found `}`
// trailing-comma.rs:16         } => assert_eq!((1, 2), (x, y)),
//                              ^
// task 'rustc' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/libsyntax/diagnostic.rs:75
// task '<main>' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/librustc/lib.rs:400
fn test_match() {
    match a {
        A {
            long_field_name_1: x,
            long_field_name_2: y,
        } => assert_eq!((1, 2), (x, y)),
    }
}

// trailing-comma.rs:27:4: 27:5 error: expected ident, found `}`
// trailing-comma.rs:27     } = a;
//                          ^
// task 'rustc' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/libsyntax/diagnostic.rs:75
// task '<main>' failed at 'explicit failure', /Users/brendan/dev/rust/rust/src/librustc/lib.rs:400
fn test_let() {
    let A {
        long_field_name_1: x,
        long_field_name_2: y,
    } = a;
    assert_eq!((1, 2), (x, y));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of Rust

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions