Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for RFC 2388, reserve the `try` keyword and resolve `do catch { .. }` syntax question with `try { .. }` #50412

Closed
Centril opened this Issue May 3, 2018 · 24 comments

Comments

Projects
None yet
@Centril
Copy link
Contributor

Centril commented May 3, 2018

This is a tracking issue for the RFC "Reserve try for try { .. } block expressions" (rust-lang/rfcs#2388).

This issue only tracks the keyword reservation in edition 2018,
and renaming do catch { .. } to try { .. }.
For the main issue, see #31436.

Steps:

Unresolved questions:

  • Should try!(expr) still work in edition 2018+? If so, how exactly should it?
    Resolution: it should not.
@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented May 3, 2018

Ensure that try { .. } $ident { .. } does not parse (so that we have options for try { .. } catch { .. }).

Huh this is not mentioned in the RFC at all.

(Currently do catch { stuff } $ident { ... } won't typecheck because () is not Try)

@Centril

This comment has been minimized.

Copy link
Contributor Author

Centril commented May 3, 2018

Huh this is not mentioned in the RFC at all.

It's discussed in the RFC comments tho :) This is just future proofing.

I'm not saying we should necessarily add catch handlers, but if we let try { .. } catch { .. } parse and stabilize it as such, then afaik you forfeit the ability to add catch / match / else / .. after.

But if we can solve the struct catch; try { .. } catch { .. } problem by not letting () implement Try then I suppose you future proof that way too?

@est31

This comment has been minimized.

Copy link
Contributor

est31 commented May 3, 2018

Where is the part that the try macro should still be allowed? What happened to that?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 3, 2018

As I mentioned to @est3I believe that we ought to be able to support try! as a kind of "special case" in the parser. Seems worth adding as an unresolved question, at least (this would basically be a kind of contextual keyword). I'd still however prefer that in Rust 2018 try! the macro is deprecated (and warns you, suggesting a rewrite to use ? -- though perhaps not a "rustfix-enabled" rewrite). At minimum I suppose we can rewrite to r#try!(...).

@Centril

This comment has been minimized.

Copy link
Contributor Author

Centril commented May 3, 2018

@nikomatsakis

Seems worth adding as an unresolved question

Done :)

@Centril

This comment has been minimized.

Copy link
Contributor Author

Centril commented May 4, 2018

cc @Manishearth on try! in edition 2018.

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented May 5, 2018

@Centril I think work here is currently blocked on #50307

@est31

This comment has been minimized.

Copy link
Contributor

est31 commented May 13, 2018

Very interesting cpp proposal just as this RFC wants to bury try!(expr): they want to add try expr expressions.

A big point for this RFC was familiarity with other languages. Now as finally other languages are becoming familiar to us we get rid of those now familiar components and adopt their legacy idioms. This isn't really good.

So why not be consistent with Cpp here and adopt their try expr expressions? Then instead of try!(expr) and expr? you could write try expr, just like that Cpp proposal says.

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented May 13, 2018

@est31 That paper is consistent with this RFC's use of try, as its try expressions are still marking areas in which exceptions are possible, not every call which can throw. From 4.5.2 (p38):

try return “xyzzy”s + “plover”;             // ok, covers both “”s and +
return try “xyzzy”s + “plover”;             // same

If it were like ?, then it'd need to be this other example from the section, but it's explicitly not needed

return try ((try “xyzzy”s) + “plover”);     // ok, but redundant

Overall, the paper's try expr feels more like the Automatic “?” inside try {…} blocks IRLO thread.

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Jun 6, 2018

I'm yet to see a good explanation of the semantics of all this try business... it looks nasty to me, but what is it?

@Nemo157

This comment has been minimized.

Copy link
Contributor

Nemo157 commented Jun 6, 2018

@alexreg see "catch { ... } expressions" on the other tracking issue linked in the OP, this issue is just about renaming those from their current implementation of do catch { ... } to try { ... }.

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Jun 6, 2018

@Nemo157 Okay, that makes the semantics of try { ... } clear, but I still don’t get what try { ... } catch { ... } should do...

@cramertj

This comment has been minimized.

Copy link
Member

cramertj commented Jun 6, 2018

@alexreg catch { ... } wouldn't exist, only let _: Result<...> = try { ... };

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Jun 6, 2018

@cramertj Oh good. Just scoping of the ? operator in other words? Changing its exit behaviour.

@glmdgrielson

This comment has been minimized.

Copy link

glmdgrielson commented Jul 21, 2018

Wait, why does this need to be an unconditional keyword? I'm a bit uncomfortable about this since this means that code somebody just copied may break when pasted into a new file for no obvious reason. Why can't we handle it like union? What's the difference?

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 21, 2018

@glmdgrielson See the discussion in #31436. In short,

struct try { a: Option<u32> }

let a = Some(1);
let b = try { a }; // is this a `try` expression or a struct literal?
@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Jul 21, 2018

@glmdgrielson The difference with union is that it's always followed by an ident, so it can be disambiguated with one token of lookahead, since ident ident is never a valid expression. And that's helped by the fact that union is an item, so in most places it's obvious, since .union or (union or similar can't be items and pub union (or just union outside a fn) can't be an expression.

bors added a commit that referenced this issue Jul 28, 2018

Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

Fixes #52604
cc #31436 #50412

@scottmcm scottmcm added this to the Rust 2018 Release milestone Aug 6, 2018

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Aug 6, 2018

Added this to the edition milestone for tracking purposes, since this issue is all about restricting in the edition. (For extra clarity: stabilization of the feature is #31436, which is not part of the edition.)

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 22, 2018

Rollup merge of rust-lang#52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

~~Fix​es rust-lang#52604 That was fixed by PR rust-lang#53135
cc rust-lang#31436 rust-lang#50412

bors added a commit that referenced this issue Aug 23, 2018

Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

~~Fix​es #52604 That was fixed by PR #53135
cc #31436 #50412

bors added a commit that referenced this issue Aug 23, 2018

Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

~~Fix​es #52604 That was fixed by PR #53135
cc #31436 #50412

bors added a commit that referenced this issue Aug 23, 2018

Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

~~Fix​es #52604 That was fixed by PR #53135
cc #31436 #50412
@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Aug 23, 2018

I was mislead by the title of this RFC. I thought it was only about reserving the keyword to have another option available for a later decision. The title should have indicated that it also makes a "normative" change to syntax introduced in a previously-accepted RFC.

@SimonSapin SimonSapin changed the title Tracking issue for RFC 2388, "Reserve `try` for `try { .. }` block expressions" Tracking issue for RFC 2388, reserve the `try` keyword and replace `do catch { .. }` syntax with `try { .. }` Aug 23, 2018

@scottmcm scottmcm changed the title Tracking issue for RFC 2388, reserve the `try` keyword and replace `do catch { .. }` syntax with `try { .. }` Tracking issue for RFC 2388, reserve the `try` keyword and resolve `do catch { .. }` syntax question with `try { .. }` Aug 23, 2018

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Nov 8, 2018

visted for T-compiler triage. It seems like progress here has ... stalled? Does someone own the remaining steps here, given that it is on the 2018 Release Milestone?

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Nov 8, 2018

also, tagging as P-high

@pnkfelix pnkfelix added the P-high label Nov 8, 2018

@Centril

This comment has been minimized.

Copy link
Contributor Author

Centril commented Nov 8, 2018

@pnkfelix I believe that everything edition sensitive has been done wrt. keyword reservation and such.

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Nov 8, 2018

I've checked the checkboxes above:

So I think we're good to close this one?

@Centril

This comment has been minimized.

Copy link
Contributor Author

Centril commented Nov 8, 2018

@scottmcm yeah I think we can close it... should we perhaps open a new tracking issue for try { ... } ?

@Centril Centril closed this Nov 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.