Skip to content

Suggestion to remove ? #59756

Description

@varkor
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`F-try_blocks`#![feature(try_blocks)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions