title: Why does matching a Result require an explicit Err when changing the type of the Result?
body: <p>I have a match expression that I would like to potentially return an error from. It seems that the compiler is not able to infer that the last case <code>e</code> is an <code>Err(String)</code> and requires the pattern to be explicit:</p>
  
  <pre><code>fn foo() -&gt; Result&lt;Option&lt;u8&gt;, String&gt; {
      unimplemented!() // don't mind the panic here
  }
  
  fn foo2() -&gt; Result&lt;u8, String&gt; {
      let bar = foo();
  
      for _ in 0..3 {
          let baz = match bar {
              Ok(Some(b)) =&gt; b,
              Ok(None)    =&gt; continue,
              Err(e)      =&gt; return Err(e) // works
  //          e           =&gt; return e      // error[E0308]
          };
      }
  
      Ok(0)
  }
  
  fn main() {
      let _ = foo2();
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; src/main.rs:13:33
     |
  13 |           e           =&gt; return e      // error[E0308]
     |                                 ^ expected u8, found enum `std::option::Option`
     |
     = note: expected type `std::result::Result&lt;u8, _&gt;`
                found type `std::result::Result&lt;std::option::Option&lt;u8&gt;, _&gt;`
  </code></pre>
  
  <p>I'm pretty sure I have exhausted all the <code>Ok(_)</code> variants, so the only one left should be <code>Err(_)</code>. This error doesn't occur if <code>foo()</code> returns <code>Result&lt;u8, String&gt;</code>, for instance. Am I missing anything?</p>