File tree 2 files changed +36
-5
lines changed
2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -267,11 +267,12 @@ pub fn parse_failure_msg(tok: Token) -> String {
267
267
268
268
/// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
269
269
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
275
276
}
276
277
}
277
278
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments