Skip to content

Commit 38eab2e

Browse files
committed
Auto merge of #42364 - alexcrichton:beta-next, r=brson
[beta] Fix regression in `macro_rules!` name matching. This is a backport of #42005
2 parents 0308c98 + 1fc111c commit 38eab2e

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,12 @@ pub fn parse_failure_msg(tok: Token) -> String {
267267

268268
/// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
269269
fn token_name_eq(t1 : &Token, t2 : &Token) -> bool {
270-
match (t1,t2) {
271-
(&token::Ident(id1),&token::Ident(id2))
272-
| (&token::Lifetime(id1),&token::Lifetime(id2)) =>
273-
id1.name == id2.name,
274-
_ => *t1 == *t2
270+
if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
271+
id1.name == id2.name
272+
} else if let (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
273+
id1.name == id2.name
274+
} else {
275+
*t1 == *t2
275276
}
276277
}
277278

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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
/// A compile-time map from identifiers to arbitrary (heterogeneous) expressions
12+
macro_rules! ident_map {
13+
( $name:ident = { $($key:ident => $e:expr,)* } ) => {
14+
macro_rules! $name {
15+
$(
16+
( $key ) => { $e };
17+
)*
18+
// Empty invocation expands to nothing. Needed when the map is empty.
19+
() => {};
20+
}
21+
};
22+
}
23+
24+
ident_map!(my_map = {
25+
main => 0,
26+
});
27+
28+
fn main() {
29+
my_map!(main);
30+
}

0 commit comments

Comments
 (0)