-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add catch {} to AST #39921
Add catch {} to AST #39921
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
Note that only the last commit of this is new-- the rest will be rebased away once #39864 is merged in. |
7e5431f
to
cb565df
Compare
#![allow(dead_code)] | ||
#![feature(catch_expr)] | ||
|
||
struct catch {} //~ ERROR expected identifier, found keyword `catch` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for local variables? Just want to make sure that this works:
fn main() {
let catch = 0;
}
It'd also might be good to see if we can get a better error here (i.e., "catch
cannot be used as a struct name").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need a test for enum variants:
enum Foo {
catch { ... }
}
We should also test for unit- and tuple-like like structs/variants (struct catch
, struct catch(u32)
, etc).
src/libsyntax/parse/parser.rs
Outdated
@@ -468,6 +468,12 @@ impl<'a> Parser<'a> { | |||
} | |||
} | |||
|
|||
pub fn error_if_typename_is_catch(&mut self, ident: ast::Ident) { | |||
if ident.name == keywords::Catch.name() { | |||
self.span_err(self.span, "expected identifier, found keyword `catch`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer "cannot use catch
as the name of a type"
cb565df
to
11a322f
Compare
Github, why do you insist on ordering my commits in chronological order rather than log order? For those reading who are confused: the new commits in this PR are |
11a322f
to
e2f0332
Compare
Trying a crater run for commits fc6f092 to e2f0332077ec6ddcf4239ec68dc6a8324b485600. |
src/libsyntax/parse/parser.rs
Outdated
@@ -3782,8 +3782,13 @@ impl<'a> Parser<'a> { | |||
} | |||
|
|||
fn is_catch_expr(&mut self) -> bool { | |||
self.token.is_keyword(keywords::Catch) && | |||
self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) | |||
if self.restrictions.contains(Restrictions::RESTRICTION_NO_STRUCT_LITERAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it matters, but this would be cleaner as !self.restrictions.contains(...) && self.token.is_keyword(keywords::Catch) && ...
☔ The latest upstream changes (presumably #40091) made this pull request unmergeable. Please resolve the merge conflicts. |
d592d34
to
87917bd
Compare
@nikomatsakis any word from crater? |
#![allow(dead_code)] | ||
#![feature(catch_expr)] | ||
|
||
struct catch {} //~ ERROR cannot use `catch` as the name of a type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you separate struct catch
and struct catch {}
?
Can't you place them in a single file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the first one has been hit, no more errors are generated.
match catch { | ||
_ => {} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for:
let catch_result = catch {
let catch = false;
catch
};
Will that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would work, but I don't see anything particularly special about that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know.
☔ The latest upstream changes (presumably #40008) made this pull request unmergeable. Please resolve the merge conflicts. |
87917bd
to
6e94329
Compare
I'm trying yet another crater run. I keep getting timeouts. Perhaps this latest round was due to S3. |
And...I'm an idiot. I've been fat-fingering the URL to your repo @cramertj, sorry. Hopefully my new crater runs will work better. =) |
OK, here are the results: https://gist.github.com/nikomatsakis/d26c0ac1a6ba2ebfd6164010a679b57a The TL;DR is that there is one package found to be affected, which is the gluon-lang package (cc @Marwes). I am debating the best way to go forward here, given that crater represents an incomplete glimpse into existing Rust code. (cc @rust-lang/lang) (Context for @Marwes and @rust-lang/lang : the |
@nikomatsakis It is actually this macro https://github.com/gluon-lang/gluon/blob/master/vm/src/api.rs#L1379-L1392 called from https://github.com/gluon-lang/gluon/blob/3a12f66d741ba843e5e85fa8f8d18ef7438284f7/src/io.rs#L222 that is the error. The struct isn't used directly so the struct's name isn't important as it is only a "field name" for a record type ( It wouldn't be impossible for me to make the macro avoid generating structs as it does now but it isn't entirely trivial either. |
@cramertj so I think we need to have a bigger discussion about keywords. I'm feeling a bit less comfortable with the "just change it" -- though that may be the eventual decision. I'm wondering if, to keep this implementation going forward, we should consider something hacky and temporary, such as one of the following:
|
@nikomatsakis If we're going to make something up to avoid breakage, why not just prefix it with an unused keyword? (e.g As for the eventual solution, I'm leaning towards "just change it." This feels like pretty minor breakage, and the motivations are clear. WRT the bigger conversation about keywords, I think keyword additions in RFCs must be viewed as breaking changes unless they are accompanied by a disambiguation strategy. Conversations like the one we're having here should be part of the RFC process. |
I think this should count as a 'minor breaking change' i.e., we'll do it with a warning cycle, but still break people without bumping the major version number. Because:
|
☔ The latest upstream changes (presumably #40216) made this pull request unmergeable. Please resolve the merge conflicts. |
@eddyb Yeah, I know. haha. I'm just getting tired of bugging other ppl about it and thought I'd try yelling at bors myself. |
⌛ Testing commit b1aa993 with merge 1f982c7... |
💔 Test failed - status-travis |
@bors retry
|
⌛ Testing commit b1aa993 with merge 1174165... |
💔 Test failed - status-travis |
|
I'll wait for @alexcrichton this time |
@bors: retry
|
⌛ Testing commit b1aa993 with merge 6be9825... |
💔 Test failed - status-travis |
Travis says:
|
@bors: retry
|
☀️ Test successful - status-appveyor, status-travis |
…sakis Implement `?` in catch expressions Builds on rust-lang#39921. Final part of rust-lang#39849. r? @nikomatsakis
Part of #39849. Builds on #39864.