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

Suggestion to remove ? #59756

Closed
varkor opened this issue Apr 6, 2019 · 0 comments · Fixed by #59859
Closed

Suggestion to remove ? #59756

varkor opened this issue Apr 6, 2019 · 0 comments · Fixed by #59859
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. F-try_blocks `#![feature(try_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Apr 6, 2019

struct A;
struct B;

fn foo() -> Result<A, B> {
    Ok(A)
}

fn bar() -> Result<A, B> {
    foo()?
}

produces:

error[E0308]: try expression alternatives have incompatible types
 --> src/lib.rs:9:5
  |
9 |     foo()?
  |     ^^^^^^ expected enum `std::result::Result`, found struct `A`
  |
  = note: expected type `std::result::Result<A, B>`
             found type `A`

It would be helpful if Rust suggested removing the ? here, as without it, the function has the correct return type.

@varkor varkor added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Apr 6, 2019
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-catch labels Apr 6, 2019
@davidtwco davidtwco self-assigned this Apr 7, 2019
Centril added a commit to Centril/rust that referenced this issue Apr 12, 2019
Suggest removing `?` to resolve type errors.

Fixes rust-lang#59756.
@fmease fmease added F-try_blocks `#![feature(try_blocks)]` and removed A-catch labels Apr 17, 2024
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`. F-try_blocks `#![feature(try_blocks)]` 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.

4 participants