-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
try bikeshed: What should the syntax be? #154128
Copy link
Copy link
Open
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-try_blocks`#![feature(try_blocks)]``#![feature(try_blocks)]`T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-try_blocks`#![feature(try_blocks)]``#![feature(try_blocks)]`T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
(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.