Skip to content

Comma not allowed after last field in struct destructuring #10392

Closed

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));
}

Activity

  1. added a commit that references this issue on Dec 19, 2013
    bfb760c
  2. added 4 commits that reference this issue on Dec 20, 2013
    49fc9c9
    810c4de
  3. added a commit that references this issue on Mar 21, 2021
  4. added a commit that references this issue on Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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