rust-lang / rust-lang/rust

`try{}`: What does homogeneity mean for `Poll`?

Open
#155,368 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

F-try_blocks F-try_trait_v2 needs-triage T-lang T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The idea of https://github.com/rust-lang/rfcs/pull/3721 is that you get "the same" thing out of try { x? }.

However, there's currently no requirement that that actually happen in either the trait nor the desugaring.

As usual, Poll is the problem child for this: https://doc.rust-lang.org/std/task/enum.Poll.html#impl-Try-for-Poll%3COption%3CResult%3CT,+E%3E%3E%3E

Some potential options:

  1. Add a bound like type Residual: Residual<Self::Output, TryType = Self>; to the Try trait so that this can't happen any more.
    • that insists on separately-coloured residuals. This would require changing the residual types for Poll to be distinct, and to update the FromResidual implementations accordingly to continue to support stable things.
  2. Give up and say "meh, whatever" and try { my_poll? } will give a Result or an Option.
  3. Add a bound into the desugaring for ? or try { somehow that would enforce that it's usable only on Try types with full homogeneity
    • perhaps merge the branch+from_residual into one helper function that calls both but which has some extra where bounds

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read RFC 3721 and the linked Poll implementation, then trace the Try trait and try-block/? desugaring. Compare the three options in the issue and document or implement the selected homogeneity rule, including compatibility implications for Poll residuals and FromResidual implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.