diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-01-27 14:41:24 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-01-27 16:42:07 -0800 |
| commit | 915242af7ac6f9fb61fe1a5416a6b6974502825b (patch) | |
| tree | 3da68e196ba6b041d8a981f8d8368f666b684e2a /src/libsyntax/parse | |
| parent | 30ae115a1d92a22449825252d990e2e89c2e1e98 (diff) | |
| parent | d83687f68c1eed7d9783d23a7464e93aa5e886c3 (diff) | |
| download | rust-915242af7ac6f9fb61fe1a5416a6b6974502825b.tar.gz rust-915242af7ac6f9fb61fe1a5416a6b6974502825b.zip | |
Rollup merge of #39335 - cramertj:cramertj/can_begin_expr_fix, r=petrochenkov
Fix can_begin_expr keyword behavior Partial fix for #28784.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index d9e47a6b56e..0f0c6d0ca83 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -80,6 +80,28 @@ impl Lit { } } +fn ident_can_begin_expr(ident: ast::Ident) -> bool { + let ident_token: Token = Ident(ident); + + !ident_token.is_any_keyword() || + ident_token.is_path_segment_keyword() || + [ + keywords::Box.name(), + keywords::Break.name(), + keywords::Continue.name(), + keywords::False.name(), + keywords::For.name(), + keywords::If.name(), + keywords::Loop.name(), + keywords::Match.name(), + keywords::Move.name(), + keywords::Return.name(), + keywords::True.name(), + keywords::Unsafe.name(), + keywords::While.name(), + ].contains(&ident.name) +} + #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)] pub enum Token { /* Expression-operator symbols. */ @@ -163,7 +185,7 @@ impl Token { pub fn can_begin_expr(&self) -> bool { match *self { OpenDelim(..) => true, - Ident(..) => true, + Ident(ident) => ident_can_begin_expr(ident), Literal(..) => true, Not => true, BinOp(Minus) => true, |
