Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd catch {} to AST #39921
Conversation
rust-highfive
assigned
eddyb
Feb 17, 2017
This comment has been minimized.
This comment has been minimized.
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
cramertj
changed the title
Add Catch to AST
Add catch {} to AST
Feb 17, 2017
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
nikomatsakis
and unassigned
eddyb
Feb 17, 2017
This comment has been minimized.
This comment has been minimized.
|
Note that only the last commit of this is new-- the rest will be rebased away once #39864 is merged in. |
cramertj
force-pushed the
cramertj:add-catch-to-ast
branch
from
7e5431f
to
cb565df
Feb 18, 2017
nikomatsakis
reviewed
Feb 22, 2017
| #![allow(dead_code)] | ||
| #![feature(catch_expr)] | ||
|
|
||
| struct catch {} //~ ERROR expected identifier, found keyword `catch` |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Feb 22, 2017
Contributor
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").
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Feb 22, 2017
Contributor
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).
nikomatsakis
reviewed
Feb 22, 2017
| @@ -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`"); | |||
This comment has been minimized.
This comment has been minimized.
cramertj
force-pushed the
cramertj:add-catch-to-ast
branch
from
cb565df
to
11a322f
Feb 22, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
cramertj
force-pushed the
cramertj:add-catch-to-ast
branch
from
11a322f
to
e2f0332
Feb 23, 2017
This comment has been minimized.
This comment has been minimized.
cramertj
reviewed
Feb 23, 2017
| @@ -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) { | |||
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 23, 2017
Author
Member
Not that it matters, but this would be cleaner as !self.restrictions.contains(...) && self.token.is_keyword(keywords::Catch) && ...
This comment has been minimized.
This comment has been minimized.
|
|
cramertj
force-pushed the
cramertj:add-catch-to-ast
branch
from
d592d34
to
87917bd
Feb 25, 2017
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis any word from crater? |
KalitaAlexey
suggested changes
Feb 27, 2017
| #![allow(dead_code)] | ||
| #![feature(catch_expr)] | ||
|
|
||
| struct catch {} //~ ERROR cannot use `catch` as the name of a type |
This comment has been minimized.
This comment has been minimized.
KalitaAlexey
Feb 27, 2017
Contributor
Why did you separate struct catch and struct catch {}?
Can't you place them in a single file?
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 28, 2017
•
Author
Member
Once the first one has been hit, no more errors are generated.
| match catch { | ||
| _ => {} | ||
| }; | ||
| } |
This comment has been minimized.
This comment has been minimized.
KalitaAlexey
Feb 27, 2017
Contributor
Could you add a test for:
let catch_result = catch {
let catch = false;
catch
};Will that work?
This comment has been minimized.
This comment has been minimized.
cramertj
Feb 28, 2017
Author
Member
Yes, it would work, but I don't see anything particularly special about that case.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
cramertj
force-pushed the
cramertj:add-catch-to-ast
branch
from
87917bd
to
6e94329
Feb 28, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm trying yet another crater run. I keep getting timeouts. Perhaps this latest round was due to S3. |
This comment has been minimized.
This comment has been minimized.
|
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. =) |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
@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:
|
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@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. |
bors
added a commit
that referenced
this pull request
Mar 12, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 12, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
I'll wait for @alexcrichton this time |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 13, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Travis says:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Mar 14, 2017
This comment has been minimized.
This comment has been minimized.
|
|
cramertj commentedFeb 17, 2017
Part of #39849. Builds on #39864.