rust-lang / rust-lang/rust

`try bikeshed`: What type should be annotated?

Open
#154,127 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-discussion F-try_blocks T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

(Sub-issue of #149488. Related to future work from https://github.com/rust-lang/rfcs/pull/3721.)

As currently implemented on nightly, if you want to convert a bunch of stuff to a particular error, you use something like

try bikeshed Result<_, io::Error> { … }

That might sometimes be useful if we actually want to write the ok type, but often it seems like it's just _, because of course the body of the block ends up having specified that type anyway.

In terms of the try_trait_v2 model, however, it would in a sense make more sense to residual type. That doesn't have the "extra" type of the ok part, since it's arguably not the point.

But in the implementations of the traits that doesn't really make much sense, because writing out the residual type isn't actually any easier:

try bikeshed Result<!, io::Error> { … }

But maybe introducing a something like a family type would work? (Could use that instead of "residual" in the naming too.)

If that became a common thing to use and name, we could do something like

try bikeshed anyhow::Family { … }

Though that's not necessarily any different from type Family = Result<!, anyhow::Result>;.

We could also imagine taking something that's not a complete type, like have try bikeshed anyhow::Result taking a type constructor instead, though I think that's currently unprecedented in Rust so might be too weird.

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 parent issue #149488 and the related RFC 3721 pull request first, then examine the try_trait_v2 model and the proposed try bikeshed examples. Done means reaching an agreed design for which type or type-like construct the annotation should accept, including a rationale and representative syntax.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.