Skip to content

Bogus error when using .. in struct expr with all fields present, in a const ("error[E0016]: blocks in constants are limited to items and tail expressions") #39161

Closed
@jorendorff

Description

@jorendorff
struct X { a: i32, b: i32 }

#[allow(unused_variables)]
fn main() {
    const DX: X = X { a: 0, b: 0 };
    const X1: X = X { a: 1, ..DX };  // ok
    let   x2    = X { a: 1, b: 2, ..DX };  // ok
    const X3: X = X { a: 1, b: 2, ..DX };  // error[E0016]
}
  • It's weird that X1 and x2 are allowed, but not X3.
  • Even if that's intentional, the error message seems off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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