Skip to content

Type inference for ? operator #1426

Closed
Closed
@flodiebold

Description

@flodiebold

Now that basic support for associated types is there, we should be able to
implement type inference for the ? operator. For example, in

let x = Ok(1u32);
let y = x?;
y;

hovering y should say u32.

Like for loops, rustc implements the ? operator via desugaring.
So the same thing as there goes here: we could do the same, but it's probably
simpler for now to handle them directly during type inference.

This should work very similarly as for loops, so basically the same steps as
there apply, except we need to project to std::ops::Try::Ok. Note that we
don't really care about the error part at this moment, because there are no
types to be inferred there -- the error type almost always needs to be already
known because Into is used to convert it to the function's error type.

Since this shares a few steps and the general approach with for, I'd suggest
doing one after the other.

Here's a Zulip stream for questions about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-has-instructionsIssue has some instructions and pointers to code to get startedE-mediumfunA technically challenging issue with high impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions