diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-30 04:22:09 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-30 04:22:09 +0200 |
| commit | f3a3290ba36b66ee091f6442fe7f0a22dc57941b (patch) | |
| tree | 24037cbb4021d0a7c94f972a3031e6d9981f0fe3 /src/libsyntax/parse | |
| parent | 04b88a9eba8abbac87eddcb2998beea09589c2c9 (diff) | |
| download | rust-f3a3290ba36b66ee091f6442fe7f0a22dc57941b.tar.gz rust-f3a3290ba36b66ee091f6442fe7f0a22dc57941b.zip | |
Account for maybe_whole_expr in range patterns.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6cb965bf817..2fa6d20430b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3741,6 +3741,7 @@ impl<'a> Parser<'a> { self.token.is_path_start() // e.g. `MY_CONST`; || self.token == token::Dot // e.g. `.5` for recovery; || self.token.can_begin_literal_or_bool() // e.g. `42`. + || self.token.is_whole_expr() } // Helper function to decide whether to parse as ident binding diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 472e4b474d6..d6d13c19f71 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -476,6 +476,19 @@ impl Token { false } + /// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`? + /// That is, is this a pre-parsed expression dropped into the token stream + /// (which happens while parsing the result ofmacro expansion)? + crate fn is_whole_expr(&self) -> bool { + if let Interpolated(ref nt) = self.kind { + if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = **nt { + return true; + } + } + + false + } + /// Returns `true` if the token is either the `mut` or `const` keyword. crate fn is_mutability(&self) -> bool { self.is_keyword(kw::Mut) || |
