Skip to content

Provide hint when field default is of a concrete type and the field type is or contains a rigid generic param that has a default #147748

@camsteffen

Description

@camsteffen

I expected to be able to write:

struct Foo<T = String> {
    x: T = String::new(),
}

but I got this error:

error[E0308]: mismatched types
 --> src/lib.rs:4:12
  |
3 | struct Foo<T = String> {
  |            ---------- expected this type parameter
4 |     x: T = String::new(),
  |            ^^^^^^^^^^^^^ expected type parameter `T`, found `String`
  |
  = note: expected type parameter `T`
                     found struct `String`

It seems like this ought to work. But if not, we should at least improve the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-type-systemArea: Type systemD-papercutDiagnostics: An error or lint that needs small tweaks.F-default_field_values`#![feature(default_field_values)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions