You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
try bikeshed: What type should be annotated? #154127
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.
Initial vibe: trying to name something shorter than the overall type seems awkwardly different from anything else in the language, and limits what we can do with this construct.
I suspect, in practice, that people might end up writing helper macros to use in place of heterogeneous try. For instance, eyretry! { } in place of try bikeshed eyre::Result<_>.
for the eyre example at least we recently added a default for the T param on our Result alias so presumably eyre users would simply write try bikeshed eyre::Result { once that change is released.
Beyond that, my feeling is that simply using type itself as currently implemented is fine actually. It's not that many extra characters to write and as eyre already demonstrates its quite simple to add an alias that lets you remove that small extra bit of boiler plate if it's bothering you.
Activity
joshtriplett commentedon Mar 25, 2026
Initial vibe: trying to name something shorter than the overall type seems awkwardly different from anything else in the language, and limits what we can do with this construct.
I suspect, in practice, that people might end up writing helper macros to use in place of heterogeneous
try. For instance,eyretry! { }in place oftry bikeshed eyre::Result<_>.yaahc commentedon Mar 31, 2026
for the eyre example at least we recently added a default for the T param on our
Resultalias so presumably eyre users would simply writetry bikeshed eyre::Result {once that change is released.Beyond that, my feeling is that simply using type itself as currently implemented is fine actually. It's not that many extra characters to write and as eyre already demonstrates its quite simple to add an alias that lets you remove that small extra bit of boiler plate if it's bothering you.
unresolved questions: