<h2 dir="auto">Code</h2>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn foo1(x: &amp;str) {
        println!(&quot;foo1({})&quot;, x);
}

fn foo2(x: &amp;str) {
        println!(&quot;foo2({})&quot;, x);
}

macro_rules! wtf {
        (1) =&gt; (foo1);
        (2) =&gt; (foo2);
}

macro_rules! wtf_foo {
        ($x:expr, $num:expr) =&gt; {
                wtf!($num)($x);
        }
}

fn main() {
        //Fails
        wtf_foo!(&quot;one&quot;, 1);
        //Works
        wtf!(1)(&quot;one&quot;);
}"><pre class="notranslate"><span class="pl-k">fn</span> <span class="pl-en">foo1</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">str</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"foo1({})"</span>, x<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">foo2</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">str</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"foo2({})"</span>, x<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">macro_rules!</span> wtf <span class="pl-kos">{</span>
        <span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span> =&gt; <span class="pl-kos">(</span>foo1<span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">(</span><span class="pl-c1">2</span><span class="pl-kos">)</span> =&gt; <span class="pl-kos">(</span>foo2<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">macro_rules!</span> wtf_foo <span class="pl-kos">{</span>
        <span class="pl-kos">(</span>$x<span class="pl-kos">:</span>expr, $num<span class="pl-kos">:</span>expr<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span>
                wtf!<span class="pl-kos">(</span>$num<span class="pl-kos">)</span><span class="pl-kos">(</span>$x<span class="pl-kos">)</span>;
        <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-c">//Fails</span>
        <span class="pl-en">wtf_foo</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"one"</span>, <span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-c">//Works</span>
        <span class="pl-en">wtf</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s">"one"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h2 dir="auto">Output</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc foo.rs 
foo.rs:16:8: 17:12 error: no rules expected the token `1`
foo.rs:16               wtf!($num)($x);
                             ^~~~"><pre class="notranslate"><code class="notranslate">$ rustc foo.rs 
foo.rs:16:8: 17:12 error: no rules expected the token `1`
foo.rs:16               wtf!($num)($x);
                             ^~~~
</code></pre></div>
<h2 dir="auto">Expected Output</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc foo.rs 
foo.rs:5:1: 7:2 warning: function is never used: `foo2`, #[warn(dead_code)] on by default
foo.rs:5 fn foo2(x: &amp;str) {
foo.rs:6        println!(&quot;foo2({})&quot;, x);
foo.rs:7 }
$ ./foo
foo1(one)
foo1(one)"><pre class="notranslate"><code class="notranslate">$ rustc foo.rs 
foo.rs:5:1: 7:2 warning: function is never used: `foo2`, #[warn(dead_code)] on by default
foo.rs:5 fn foo2(x: &amp;str) {
foo.rs:6        println!("foo2({})", x);
foo.rs:7 }
$ ./foo
foo1(one)
foo1(one)
</code></pre></div>
<h2 dir="auto">Other</h2>
<p dir="auto">This works fine, so the problem appears to be limited to literal patterns (not sure if that's the right term):</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="macro_rules! print_stuff_for_real {
        ($x:expr) =&gt; (println!(&quot;Printing stuff: {}&quot;, $x));
}

macro_rules! print_stuff {
        ($x:expr) =&gt; (print_stuff_for_real!($x));
}

fn main() {
        print_stuff!(&quot;stuff&quot;);
}
"><pre class="notranslate"><span class="pl-k">macro_rules!</span> print_stuff_for_real <span class="pl-kos">{</span>
        <span class="pl-kos">(</span>$x<span class="pl-kos">:</span>expr<span class="pl-kos">)</span> =&gt; <span class="pl-kos">(</span>println!<span class="pl-kos">(</span><span class="pl-s">"Printing stuff: {}"</span>, $x<span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">macro_rules!</span> print_stuff <span class="pl-kos">{</span>
        <span class="pl-kos">(</span>$x<span class="pl-kos">:</span>expr<span class="pl-kos">)</span> =&gt; <span class="pl-kos">(</span>print_stuff_for_real!<span class="pl-kos">(</span>$x<span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">print_stuff</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"stuff"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h2 dir="auto">Meta</h2>
<p dir="auto">I used two versions of rustc; they behaved identically.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-unknown-linux-gnu
release: 1.0.0"><pre class="notranslate"><code class="notranslate">rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-unknown-linux-gnu
release: 1.0.0
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 1.2.0-nightly (f76d9bcfc 2015-05-28) (built 2015-05-28)
binary: rustc
commit-hash: f76d9bcfc2c269452522fbbe19f66fe653325646
commit-date: 2015-05-28
build-date: 2015-05-28
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly"><pre class="notranslate"><code class="notranslate">rustc 1.2.0-nightly (f76d9bcfc 2015-05-28) (built 2015-05-28)
binary: rustc
commit-hash: f76d9bcfc2c269452522fbbe19f66fe653325646
commit-date: 2015-05-28
build-date: 2015-05-28
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly
</code></pre></div>
<p dir="auto">With the exception of metavariables with <code class="notranslate">ident</code> and <code class="notranslate">tt</code> fragment specifiers, a macro that passes a metavariable into another macro which contains the raw tokens specified by that metavariable in the matcher will throw a <code class="notranslate">no rules expected the token `{tokens}`</code> error, despite the raw tokens matching up.</p>
<p dir="auto">The code in this gist should all compile, but doesn't with the given error messages: <a href="https://gist.github.com/Osspial/d0eb4827d764aa40912bface538dd0ea">https://gist.github.com/Osspial/d0eb4827d764aa40912bface538dd0ea</a></p>
<h2 dir="auto">Meta</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt; rustc --version --verbose
rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: x86_64-pc-windows-gnu
release: 1.16.0
LLVM version: 3.9"><pre class="notranslate"><code class="notranslate">&gt; rustc --version --verbose
rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: x86_64-pc-windows-gnu
release: 1.16.0
LLVM version: 3.9
</code></pre></div>