title: How to type annotate the return value of a macro?
body: <p>Please have a look at this slightly contrived example:</p>
  
  <pre><code>use std::io::{Read, Result};
  
  macro_rules! read_u8 {
      ($r:expr) =&gt; {{
          let mut buf = [0; 1];
          $r.read_exact(&amp;mut buf)?;
          Ok(buf[0])
      }};
  }
  
  fn t&lt;R: Read&gt;(r: &amp;mut R) -&gt; Result&lt;u8&gt; {
      let x = read_u8!(r)?;
      Ok(x)
  }
  
  fn main() {
      use std::io::Cursor;
      let mut x: Cursor&lt;Vec&lt;u8&gt;&gt; = Cursor::new(vec![1, 2, 3]);
  
      match t(&amp;mut x) {
          _ =&gt; println!("Done"),
      }
  }
  </code></pre>
  
  <p>If you try to <a href="https://play.rust-lang.org/?gist=53fb0e2a89acad3a4d4e6ebdf53243d9&amp;version=stable&amp;mode=debug" rel="nofollow noreferrer">run this example</a>, you get:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0282]: type annotations needed
    --&gt; src/main.rs:12:13
     |
  12 |     let x = read_u8!(r)?;
     |             ^^^^^^^^^^^^ cannot infer type for `_`
  </code></pre>
  
  <p>How do I annotate the macro or the call site to get it to figure out I want to return the <code>Result</code> that is in scope?</p>