Skip to content

Diagnostic could be more helpful for missing comma when using .. field initialization copy operator. #51103

Closed
@vi

Description

@vi
#[derive(Default)]
struct A {
    b: u32,
    c: u64,
    d: usize,
}

fn main() {
    let q = A { c: 5 .. Default::default() };
}
error[E0308]: mismatched types
 --> src/main.rs:9:20
  |
9 |     let q = A { c: 5 .. Default::default() };
  |                    ^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found struct `std::ops::Range`
  |
  = note: expected type `u64`
             found type `std::ops::Range<{integer}>`

error[E0063]: missing fields `b`, `d` in initializer of `A`
 --> src/main.rs:9:13
  |
9 |     let q = A { c: 5 .. Default::default() };
  |             ^ missing `b`, `d`

error: aborting due to 2 previous errors

Maybe it should suggest proper syntax when there are both missing fields and std::ops::Range-related error somewhere?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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