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
6 tasks done
Centril opened this issue May 3, 2018 · 27 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-epoch Working group: Epoch (2018) management

Comments

@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.
@Centril Centril added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels May 3, 2018
@Centril Centril added WG-epoch Working group: Epoch (2018) management A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 3, 2018
@kennytm
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
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
Copy link
Member

est31 commented May 3, 2018

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

@nikomatsakis
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
Copy link
Contributor Author

Centril commented May 3, 2018

@nikomatsakis

Seems worth adding as an unresolved question

Done :)

@Centril
Copy link
Contributor Author

Centril commented May 4, 2018

cc @Manishearth on try! in edition 2018.

@scottmcm
Copy link
Member

scottmcm commented May 5, 2018

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

@est31
Copy link
Member

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
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
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
Copy link
Member

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
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
Copy link
Member

cramertj commented Jun 6, 2018

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

@alexreg
Copy link
Contributor

alexreg commented Jun 6, 2018

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

@glmdgrielson
Copy link

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
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
Copy link
Member

@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.

@scottmcm
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
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
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
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
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
Copy link
Member

pnkfelix commented Nov 8, 2018

also, tagging as P-high

@pnkfelix pnkfelix added the P-high High priority label Nov 8, 2018
@Centril
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
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
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 { ... } ?

@viper6277
Copy link

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!(...).

Newbie here....So ...how do I replace ?

r#try!(m.add(py, "test", py_fn!(py, test())));

@cramertj
Copy link
Member

m.add(py, "test", py_fn!(py, test()))?;

@viper6277
Copy link

m.add(py, "test", py_fn!(py, test()))?;

Thanks @cramertj .... run into these syntax issues all the time with rust, but I still love what the language is about, ... I've become a huge rust fan and plan on sticking with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-epoch Working group: Epoch (2018) management
Projects
None yet
Development

No branches or pull requests