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

E0277 should put emphasis on containing function's return type #63078

Closed
mibac138 opened this issue Jul 28, 2019 · 7 comments
Closed

E0277 should put emphasis on containing function's return type #63078

mibac138 opened this issue Jul 28, 2019 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mibac138
Copy link
Contributor

mibac138 commented Jul 28, 2019

I got the following error today:

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src/main.rs:29:20
   |
29 |     let mut resp = reqwest::get("...")?;
   |                    ^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

I was confused for a minute as I misinterpreted what the error was saying. I double-checked that reqwest::get does indeed return a Result but a moment later I realized that it's the function that's containing reqwest::get I should be looking at which indeed did return () after which I fixed the issue.

I believe this error message could be somehow improved and/or worded differently to put more stress on the containing function - after all, that's what I should've looked at (maybe the containing function should be even shown in the error message like reqwest::get is?) though I can see how it can not always be the case. However, I do still think both the containing method's return type and the reqwest::get call should be highlighted for the best experience and to easily allow a full understanding of what's happening.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2019
@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` labels Aug 4, 2019
@fakenine
Copy link
Contributor

fakenine commented Aug 9, 2019

Hello! I'd like to work on this one.

@ayazhafiz
Copy link
Contributor

@fakenine are you still interested in this?

@fakenine
Copy link
Contributor

fakenine commented Sep 20, 2019 via email

@chandrikamutalik
Copy link

Hello! I'd like to work on this if it's not being worked on already. @fakenine , @ayazhafiz can you guys please tell me if either of you are working on this! :)

@ayazhafiz
Copy link
Contributor

I'm not :)

@reese
Copy link
Contributor

reese commented Dec 7, 2019

As mentioned by @estebank, I think this issue is closed by #66651, which updated this error message with some more emphasis on the return type (see here).

@estebank
Copy link
Contributor

estebank commented Dec 9, 2019

Closing, since #66651 landed in nightly the output is now

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
 --> src/lib.rs:2:5
  |
1 | / fn bar() {
2 | |     foo()?;
  | |     ^^^^^^ cannot use the `?` operator in a function that returns `()`
3 | | }
  | |_- this function should return `Result` or `Option` to accept `?`
  |
  = help: the trait `std::ops::Try` is not implemented for `()`
  = note: required by `std::ops::Try::from_error`

@estebank estebank closed this as completed Dec 9, 2019
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants