Skip to content

try bikeshed: What type should be annotated? #154127

@scottmcm

Description

@scottmcm

(Sub-issue of #149488. Related to future work from rust-lang/rfcs#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.F-try_blocks`#![feature(try_blocks)]`T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions