title: Declarative macros - bracketed expressions can be followed by arbitrary matchers. Why?
body: <p>I was experimenting with declarative macros and I thought about recreating F# sequence expressions using them.
  First attempt triggered the compilation error:</p>
  <pre><code>macro_rules! genexp {
    (for $item:ident in $range:expr -&gt; $expr:expr) =&gt; {
      $range.map(|$item| $expr)
    }
  }
  
  `$range:expr` is followed by `-&gt;`, which is not allowed for `expr` fragments
  allowed there are: `=&gt;`, `,` or `;`rustc
  </code></pre>
  <p>However, following code compiles and works just fine:</p>
  <pre><code>macro_rules! genexp {
    (for $item:ident in [$range:expr] -&gt; $expr:expr) =&gt; {
      $range.map(|$item| $expr)
    }
  }
  
  fn main() {
      let foo = genexp!(for x in [0..20] -&gt; x * x);
      println!(&quot;{:?}&quot;, foo.collect::&lt;Vec&lt;_&gt;&gt;())
  }
  
  //OUTPUT: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
  </code></pre>
  <p>My question is, why?  <a href="https://doc.rust-lang.org/reference/macros-by-example.html" rel="nofollow noreferrer">Macros By Example</a> section in Rust Reference states that:</p>
  <blockquote>
  <ul>
  <li><code>expr</code> and <code>stmt</code> may only be followed by one of: <code>=&gt;</code>, <code>,</code>, or <code>;</code>.</li>
  </ul>
  </blockquote>
  <p>I see no info about special treatment of various brackets or other delimiters.</p>