Skip to content

Suggest missing comma on last field before struct update syntax #100300

Closed
@Havvy

Description

@Havvy

Given the following code: [Playground]

#[derive(Default)]
struct Defaultable;

#[derive(Default)]
struct HoldsDefaultable {
    defaultable: Defaultable,
}

fn main() {
    HoldsDefaultable {
      defaultable: Defaultable
      ..Default::default()
    };
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
  --> src/main.rs:11:20
   |
11 |         defaultable: Defaultable
   |  ____________________^
12 | |       ..Default::default()
   | |__________________________^ expected struct `Defaultable`, found struct `std::ops::Range`
   |
   = note: expected struct `Defaultable`
              found struct `std::ops::Range<Defaultable>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

Ideally the output should suggest adding a comma after Defaultable on line 11 if doing so would solve the type error.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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