diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-07-13 14:12:57 -0700 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-07-13 14:12:57 -0700 |
| commit | b5c5a0c3fd91e2f3a61e26bf5a00297a6e2b3366 (patch) | |
| tree | ea4e9242484a3014086f1b012d2dfa6d1247c624 | |
| parent | b2c0707872082c890f332178f59fd02eea5b98f3 (diff) | |
| download | rust-b5c5a0c3fd91e2f3a61e26bf5a00297a6e2b3366.tar.gz rust-b5c5a0c3fd91e2f3a61e26bf5a00297a6e2b3366.zip | |
Fix regression involving identifiers in `macro_rules!` patterns.
| -rw-r--r-- | src/libsyntax/ext/tt/quoted.rs | 3 | ||||
| -rw-r--r-- | src/test/run-pass/issue-40847.rs | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index 4e9e30857b1..74fa85d130b 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -196,7 +196,8 @@ fn parse_tree<I>(tree: tokenstream::TokenTree, num_captures: name_captures, })) } - Some(tokenstream::TokenTree::Token(ident_span, token::Ident(ident))) => { + Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => { + let ident = token.ident().unwrap(); let span = Span { lo: span.lo, ..ident_span }; if ident.name == keywords::Crate.name() { let ident = ast::Ident { name: keywords::DollarCrate.name(), ..ident }; diff --git a/src/test/run-pass/issue-40847.rs b/src/test/run-pass/issue-40847.rs new file mode 100644 index 00000000000..2fa99984401 --- /dev/null +++ b/src/test/run-pass/issue-40847.rs @@ -0,0 +1,26 @@ +// Copyright 2017 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. + +macro_rules! gen { + ($name:ident ( $($dol:tt $var:ident)* ) $($body:tt)*) => { + macro_rules! $name { + ($($dol $var:ident)*) => { + $($body)* + } + } + } +} + +gen!(m($var) $var); + +fn main() { + let x = 1; + assert_eq!(m!(x), 1); +} |
