Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mejrs opened this issue Apr 6, 2022 · 1 comment · Fixed by #96271
Closed

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

mejrs opened this issue Apr 6, 2022 · 1 comment · Fixed by #96271
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mejrs
Copy link
Contributor

mejrs commented Apr 6, 2022

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`.
@mejrs mejrs added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 6, 2022
@compiler-errors
Copy link
Member

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 1, 2022
…rk, r=estebank

suggest `?` when method is missing on `Result<T, _>` but found on `T`

The wording needs help, I think.

Fixes rust-lang#95729
@bors bors closed this as completed in 7d4cf71 Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants