Understanding macro with []

I'm trying to understand what this macro does: rust/arena.rs at b25d3ba78118033b3f25b6de7a32e210d113872c · rust-lang/rust · GitHub

macro_rules! arena_types {
    ($macro:path, $args:tt, $tcx:lifetime) => (
        $macro!($args, [
            // HIR types
            [few] hir_krate: rustc_hir::Crate<$tcx>,
            [] arm: rustc_hir::Arm<$tcx>,
            [] asm_operand: (rustc_hir::InlineAsmOperand<$tcx>, Span),
            [] asm_template: rustc_ast::InlineAsmTemplatePiece,
            [] attribute: rustc_ast::Attribute,
            [] block: rustc_hir::Block<$tcx>,
            [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,

It's called like this:

rustc_hir::arena_types!(rustc_arena::declare_arena, [], 'tcx);

Well, the first thing matched is a macro, the second is a tokentree which I couldn't understand what exactly is but looks like things inside [] and the third is a lifetime.

Well, I understand that the arena_types! macro applies the matched macro with the arguments, but what is the things that come after the $args? What is [few] hir_krate: rustc_hir::Crate<$tcx>,? I don't understand anything of here.

This macro is building a call to the declare_arena macro, which is sadly undocumented. There's no way to understand the contents of the [] as normal Rust code: it means whatever declare_arena decides that it means.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.