Skip to content

Commit 086eaa7

Browse files
committed
Auto merge of #43224 - jseyfried:fix_macro_idents_regression, r=nrc
macros: fix regression involving identifiers in `macro_rules!` patterns. Fixes #42019. r? @nrc
2 parents a783fe2 + b5c5a0c commit 086eaa7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/libsyntax/ext/tt/quoted.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ fn parse_tree<I>(tree: tokenstream::TokenTree,
196196
num_captures: name_captures,
197197
}))
198198
}
199-
Some(tokenstream::TokenTree::Token(ident_span, token::Ident(ident))) => {
199+
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
200+
let ident = token.ident().unwrap();
200201
let span = Span { lo: span.lo, ..ident_span };
201202
if ident.name == keywords::Crate.name() {
202203
let ident = ast::Ident { name: keywords::DollarCrate.name(), ..ident };

src/test/run-pass/issue-40847.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
macro_rules! gen {
12+
($name:ident ( $($dol:tt $var:ident)* ) $($body:tt)*) => {
13+
macro_rules! $name {
14+
($($dol $var:ident)*) => {
15+
$($body)*
16+
}
17+
}
18+
}
19+
}
20+
21+
gen!(m($var) $var);
22+
23+
fn main() {
24+
let x = 1;
25+
assert_eq!(m!(x), 1);
26+
}

0 commit comments

Comments
 (0)