title: Nested iteration in Rust macros
body: <p>I'm playing with macros in Rust and want to do nested expansion, i.e. combinatorics.</p>
  
  <p>This is the code I've written:</p>
  
  <pre><code>macro_rules! nested {
      (
          $(arg $arg:ident;)*
          $(fun $fun:ident;)*
      ) =&gt; {
          $(
              $fun($($arg),*);
          )*
      }
  }
  
  fn show1(a: i32, b: i32, c: i32) {
      println!("show1: {} {} {}", a, b, c);
  }
  fn show2(a: i32, b: i32, c: i32) {
      println!("show2: {} {} {}", a, b, c);
  }
  
  fn main() {
      let a = 1;
      let b = 2;
      let c = 3;
      nested! {
          arg a;
          arg b;
          arg c;
          fun show1;
          fun show2;
      }
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=cfe3c9d319b9fd2e2cc46abfdcf18eb2&amp;version=stable&amp;backtrace=0" rel="noreferrer">Playground</a></p>
  
  <p>I want this to expand to</p>
  
  <pre><code>fn main() {
      let a = 1;
      let b = 2;
      let c = 3;
      // iteration over $fun
      show1(/* iteration over $arg */a, b, c);
      show2(/* iteration over $arg */a, b, c);
  }
  </code></pre>
  
  <p>However, it seems that Rust doesn't support this and instead complains:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: inconsistent lockstep iteration: 'fun' has 2 items, but 'arg' has 3
  </code></pre>
  
  <p>So apparently it ignores the inner iteration.</p>
  
  <p>However, if I remove one of the args, to make it 2 items for both, it still complains:</p>
  
  <pre class="lang-none prettyprint-override"><code>&lt;anon&gt;:7:18: 7:25 error: attempted to repeat an expression containing no
                    syntax variables matched as repeating at this depth
  &lt;anon&gt;:7             $fun($($arg),*);
  </code></pre>
  
  <p>Is there a way to do what I want?</p>