Skip to content

Unhelpful error when forgetting to handle a result and call a method on it #95729

Closed

Description

@mejrs

Given the following code: link

struct Foo;

impl Foo {
    fn get() -> u8 {
        42
    }
}

fn main() {
    let res: Result<_, ()> = Ok(Foo);
    res.get();
}

The current output is:

error[E0599]: no method named `get` found for enum `Result` in the current scope
   --> src/main.rs:11:9
   |
11 |     res.get();
   |         ^^^ method not found in `Result<Foo, ()>`

For more information about this error, try `rustc --explain E0599`.

Ideally the output should look like:

error[E0599]: no method named `get` found for enum `Result` in the current scope
   --> src/main.rs:11:9
   |
11 |     res.get();
   |         ^^^ method not found in `Result<Foo, ()>`

note: `Result<Foo, ()>`'s success value, `Foo`, has a method named `get`.
note: To get to the success value of a Result, the error case must be handled first.

For more information about this error, try `rustc --explain E0599`.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 6, 2022
  2. compiler-errors commented on Apr 7, 2022

    @compiler-errors
    Contributor

    @rustbot claim

  3. added 2 commits that reference this issue on Jun 1, 2022
    4089e39
    7d4cf71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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