提交 915242af 编写于 作者: A Alex Crichton

Rollup merge of #39335 - cramertj:cramertj/can_begin_expr_fix, r=petrochenkov

Fix can_begin_expr keyword behavior

Partial fix for #28784.
...@@ -80,6 +80,28 @@ pub fn short_name(&self) -> &'static str { ...@@ -80,6 +80,28 @@ pub fn short_name(&self) -> &'static str {
} }
} }
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)] #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)]
pub enum Token { pub enum Token {
/* Expression-operator symbols. */ /* Expression-operator symbols. */
...@@ -163,7 +185,7 @@ pub fn is_like_gt(&self) -> bool { ...@@ -163,7 +185,7 @@ pub fn is_like_gt(&self) -> bool {
pub fn can_begin_expr(&self) -> bool { pub fn can_begin_expr(&self) -> bool {
match *self { match *self {
OpenDelim(..) => true, OpenDelim(..) => true,
Ident(..) => true, Ident(ident) => ident_can_begin_expr(ident),
Literal(..) => true, Literal(..) => true,
Not => true, Not => true,
BinOp(Minus) => true, BinOp(Minus) => true,
......
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub fn main() {
return;
return ();
return as ();
return return as ();
return return return;
return if true {
()
} else {
()
};
loop {
return break as ();
}
return enum; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `enum`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册