Skip to content

E277 could have a more helpful error message when it occurs on a try expression #59980

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

Closed
thecodewarrior opened this issue Apr 14, 2019 · 0 comments · Fixed by #60064
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@thecodewarrior
Copy link

Currently E277's message is confusing and seemingly ambiguous when it occurs on a try (?) expression (this may not be limited to E277, it's just the one I noticed). For example, in this code:

fn the_outer_method() -> Result<(), ()> {
    the_inner_method()?;
    Ok(())
}

fn the_inner_method() -> Result<(), bool> {
    Err(true)
}
error[E0277]: the trait bound `(): std::convert::From<bool>` is not satisfied
 --> src/main.rs:6:5
  |
6 |     the_inner_method()?;
  |     ^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<bool>` is not implemented for `()`
  |
  = note: required by `std::convert::From::from`

The problem is that the_inner_method's error type is bool while the_outer_method's error type is (). In this case the error isn't too confusing, but if the try is in a chained expression (foo()?.bar()) and you're a noob it isn't clear why it wants std::convert::From<bool> implemented on ().

It doesn't necessarily even require a whole fix suggestion, all it would take is making the error only highlight the ?, as the issue is actually occuring when unwrapping the result.

error[E0277]: the trait bound `(): std::convert::From<bool>` is not satisfied
 --> src/main.rs:6:5
  |
6 |     the_inner_method()?;
  |                       ^ the trait `std::convert::From<bool>` is not implemented for `()`
  |
  = note: required by `std::convert::From::from`

Thanks!

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system labels Apr 15, 2019
@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 15, 2019
Centril added a commit to Centril/rust that referenced this issue Apr 18, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 18, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 18, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 18, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Point at try `?` on errors affecting the err match arm of the desugared code

Fix rust-lang#59980.
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 A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants