(Sub-issue of #149488)
Obviously bikeshed shouldn't literally be the syntax 🙃
Colon
Obviously the default choice for introducing types is a colon, like in let, leading to something like ``try : anyhow::Result<_> {`
However, the core trouble here is that let x: _ = and let x = are always the same, whereas try { and try: _ { would be different, as the former is homogeneous (rust-lang/rfcs#3721) and the latter heterogeneous. That inconsistency isn't great.
Arrow
Another option would be the closure-like try -> anyhow::Result<_> {, similar to || -> anyhow::Result<_> {.
At least to me that looks aesthetically nicer than the colon, but it has a similar problem: || { … } and || -> _ { … } are the same, so it doesn't give the "and there's a conversion of some sort" happening intuition.
As
Niko originally hypothesized this feature in the form of try as anyhow::Result<_> { … } back in #70941 (comment)
That's nice because it's already the case that x and x as _ are different -- the latter introduces a conversion of sorts, and as _ as _ never type-checks -- which gives a similar intuition to how try { … } and try as _ { … } would be different. Plus try as _ { try as _ { … }? } also doesn't compile for the same reason that as _ as _ doesn't compile.
Other words
Because try is the keyword and the other form is try {, anything that's not { would work -- it doesn't need to be a keyword. (This is why bikeshed is working on nightly.) So we're not limited to existing reserved words (like in or whatever) if you have a good idea.
(Sub-issue of #149488)
Obviously
bikeshedshouldn't literally be the syntax 🙃Colon
Obviously the default choice for introducing types is a colon, like in
let, leading to something like ``try : anyhow::Result<_> {`However, the core trouble here is that
let x: _ =andlet x =are always the same, whereastry {andtry: _ {would be different, as the former is homogeneous (rust-lang/rfcs#3721) and the latter heterogeneous. That inconsistency isn't great.Arrow
Another option would be the closure-like
try -> anyhow::Result<_> {, similar to|| -> anyhow::Result<_> {.At least to me that looks aesthetically nicer than the colon, but it has a similar problem:
|| { … }and|| -> _ { … }are the same, so it doesn't give the "and there's a conversion of some sort" happening intuition.As
Niko originally hypothesized this feature in the form of
try as anyhow::Result<_> { … }back in #70941 (comment)That's nice because it's already the case that
xandx as _are different -- the latter introduces a conversion of sorts, andas _ as _never type-checks -- which gives a similar intuition to howtry { … }andtry as _ { … }would be different. Plustry as _ { try as _ { … }? }also doesn't compile for the same reason thatas _ as _doesn't compile.Other words
Because
tryis the keyword and the other form istry {, anything that's not{would work -- it doesn't need to be a keyword. (This is whybikeshedis working on nightly.) So we're not limited to existing reserved words (likeinor whatever) if you have a good idea.