Skip to content

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

Closed
@mejrs

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`.

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