Skip to content

try{}: What does homogeneity mean for Poll? #155368

Description

@scottmcm

The idea of rust-lang/rfcs#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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-try_blocks`#![feature(try_blocks)]`F-try_trait_v2Tracking issue for RFC#3058T-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions