Skip to content

rustc: remove the explicit count from the lang_item macro. #11657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,27 @@ use std::hashmap::HashMap;
use std::iter::Enumerate;
use std::vec;


// Get the last "argument" (has to be done recursively to avoid phoney local ambiguity error)
macro_rules! last {
( $first:expr, $( $remainder:expr, )+ ) => ( last!( $( $remainder, )+ ) );
( $first:expr, ) => ( $first )
}

// The actual lang items defined come at the end of this file in one handy table.
// So you probably just want to nip down to the end.
macro_rules! lets_do_this {
// secondary rule to allow us to use `$num` as both an expression
// and a pattern.
(
$( $num:tt, $variant:ident, $name:expr, $method:ident; )*
) => {
lets_do_this!(count = 1 + last!($($num,)*),
$($num, $variant, $name, $method; )*)
};

(
There are $num_lang_items:expr lang items.
$( $num:pat, $variant:ident, $name:expr, $method:ident; )*
count = $num_lang_items:expr, $( $num:pat, $variant:ident, $name:expr, $method:ident; )*
) => {

pub enum LangItem {
Expand Down Expand Up @@ -207,8 +222,6 @@ pub fn collect_language_items(crate: &ast::Crate,
}

lets_do_this! {
There are 40 lang items.

// ID, Variant name, Name, Method name;
0, FreezeTraitLangItem, "freeze", freeze_trait;
1, SendTraitLangItem, "send", send_trait;
Expand Down Expand Up @@ -261,4 +274,3 @@ lets_do_this! {
38, ExchangeHeapLangItem, "exchange_heap", exchange_heap;
39, GcLangItem, "gc", gc;
}