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

Add suggestion when returning Result<_, A> when Result<_, B> is expected #47560

Closed
estebank opened this issue Jan 18, 2018 · 0 comments · Fixed by #106583
Closed

Add suggestion when returning Result<_, A> when Result<_, B> is expected #47560

estebank opened this issue Jan 18, 2018 · 0 comments · Fixed by #106583
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

When returning Result<_, A> but Result<_, B> is expected and A: Into<B>, provide a suggestion to return Ok(x?) instead:

error[E0308]: mismatched types
  --> src/bin/ruby-stacktrace.rs:86:20
   |
86 |             return version;
   |                    ^^^^^^^ expected struct `failure::Error`, found enum `ruby_stacktrace::address_finder::AddressFinderError`
   |
   = note: expected type `std::result::Result<_, failure::Error>`
              found type `std::result::Result<_, ruby_stacktrace::address_finder::AddressFinderError>`
   = help: because `ruby_stacktrace::address_finder::AddressFinderError` implements `failure::Error`, you can use `?` to coerce it:
   |
86 |             return Ok(version?);
   |                    ^^^^^^^^^^^^

Case taken from https://jvns.ca/blog/2018/01/13/rust-in-2018--way-easier-to-use/

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 18, 2018
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 20, 2020
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jun 12, 2020
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 23, 2023
…r=compiler-errors

Suggest coercion of `Result` using `?`

Fix rust-lang#47560.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jan 24, 2023
…r=compiler-errors

Suggest coercion of `Result` using `?`

Fix rust-lang#47560.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jan 25, 2023
…r=compiler-errors

Suggest coercion of `Result` using `?`

Fix rust-lang#47560.
@bors bors closed this as completed in e477cf9 Jan 25, 2023
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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