Skip to content

E0004 says "note: Option<i32> defined here" when it's not #101068

Closed
@carols10cents

Description

@carols10cents

I just noticed this regression from 1.60 to 1.61 because TRPL reasons.

Code

Given the following code:

fn main() {
    let some_option_value: Option<i32> = None;
    let Some(x) = some_option_value;
}

The current output is:

error[E0005]: refutable pattern in local binding: `None` not covered
 --> src/main.rs:3:9
  |
3 |     let Some(x) = some_option_value;
  |         ^^^^^^^ pattern `None` not covered
  |
  = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
  = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
note: `Option<i32>` defined here
  = note: the matched value is of type `Option<i32>`
help: you might want to use `if let` to ignore the variant that isn't matched
  |
3 |     let x = if let Some(x) = some_option_value { x } else { todo!() };
  |     ++++++++++                                 ++++++++++++++++++++++

Notice especially this line:

note: `Option<i32>` defined here

Which... raises a few questions...

  1. I definitely did not define Option<i32> in this code, so I don't know why this note is saying I did
  2. Or is it saying that? The note doesn't point to what it thinks "here" is.
  3. What is this note trying to tell me about, really?

Ideally the output shouldn't have this line, I don't think.

Versions with regression

This problem started with 1.61 and still exists in 1.63.0, 1.64.0-beta.3, and nightly 2022-08-25 7480389.

@rustbot modify labels: +regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions