@@ -33,12 +33,27 @@ use std::hashmap::HashMap;
33
33
use std:: iter:: Enumerate ;
34
34
use std:: vec;
35
35
36
+
37
+ // Get the last "argument" (has to be done recursively to avoid phoney local ambiguity error)
38
+ macro_rules! last {
39
+ ( $first: expr, $( $remainder: expr, ) + ) => ( last!( $( $remainder, ) + ) ) ;
40
+ ( $first: expr, ) => ( $first )
41
+ }
42
+
36
43
// The actual lang items defined come at the end of this file in one handy table.
37
44
// So you probably just want to nip down to the end.
38
45
macro_rules! lets_do_this {
46
+ // secondary rule to allow us to use `$num` as both an expression
47
+ // and a pattern.
48
+ (
49
+ $( $num: tt, $variant: ident, $name: expr, $method: ident; ) *
50
+ ) => {
51
+ lets_do_this!( count = 1 + last!( $( $num, ) * ) ,
52
+ $( $num, $variant, $name, $method; ) * )
53
+ } ;
54
+
39
55
(
40
- There are $num_lang_items: expr lang items.
41
- $( $num: pat, $variant: ident, $name: expr, $method: ident; ) *
56
+ count = $num_lang_items: expr, $( $num: pat, $variant: ident, $name: expr, $method: ident; ) *
42
57
) => {
43
58
44
59
pub enum LangItem {
@@ -207,8 +222,6 @@ pub fn collect_language_items(crate: &ast::Crate,
207
222
}
208
223
209
224
lets_do_this ! {
210
- There are 40 lang items.
211
-
212
225
// ID, Variant name, Name, Method name;
213
226
0 , FreezeTraitLangItem , "freeze" , freeze_trait;
214
227
1 , SendTraitLangItem , "send" , send_trait;
@@ -261,4 +274,3 @@ lets_do_this! {
261
274
38 , ExchangeHeapLangItem , "exchange_heap" , exchange_heap;
262
275
39 , GcLangItem , "gc" , gc;
263
276
}
264
-
0 commit comments