Skip to content

Spurious 'type annotations needed' error when a struct definition has an error #75331

Closed
@Aaron1011

Description

@Aaron1011

The following code:

struct Foo {
    val: MissingType
}

fn make_it() {
    Foo { val: Default::default() };
}

produces the following errors:

error[E0412]: cannot find type `MissingType` in this scope
 --> src/lib.rs:2:10
  |
2 |     val: MissingType
  |          ^^^^^^^^^^^ not found in this scope

error[E0283]: type annotations needed
 --> src/lib.rs:6:16
  |
6 |     Foo { val: Default::default() };
  |                ^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: cannot satisfy `_: std::default::Default`
  = note: required by `std::default::Default::default`

We should suppress the 'type annotations needed' message, since it will likely be resolved by fixing the type of val.

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.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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