`try bikeshed`: What should the syntax be?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
(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 (https://github.com/rust-lang/rfcs/pull/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 https://github.com/rust-lang/rust/issues/70941#issuecomment-612167041
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the parent issue #149488, then compare the colon, arrow, as, and other syntax proposals described here, including RFC #3721 and the earlier discussion in #70941. Done means the project has chosen and documented a syntax for distinguishing homogeneous and heterogeneous try blocks, with the relevant examples and parsing or type-checking implications resolved.
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