Skip to content

Confusing "type annotations needed" for errorneous struct field type #68507

Closed

Description

@sinkuu
struct Foo {
    x: Option<NotInScope>,
}

fn main() {
    let f = Foo {
        x: None,
    };
}
error[E0412]: cannot find type `NotInScope` in this scope
 --> src/main.rs:2:15
  |
2 |     x: Option<NotInScope>,
  |               ^^^^^^^^^^ not found in this scope

error[E0282]: type annotations needed
 --> src/main.rs:7:12
  |
7 |         x: None,
  |            ^^^^ cannot infer type for `T`

error: aborting due to 2 previous errors

This "type annotations needed" error is confusing, especially if the two error messages are apart.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-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.
    on Jan 24, 2020
  2. added a commit that references this issue on Dec 31, 2022
    abeed83
  3. added a commit that references this issue on Dec 31, 2022
    726bbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-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