title: Match expects &Result when I want to use Result
body: <p>I'm using Rust 1.15 nightly and have some code with an iterator over <code>std::io::Result&lt;std::fs::DirEntry&gt;</code> named <code>dir_contents_iterator</code> that I'm trying to partition based on whether each <code>DirEntry</code> corresponds to a file or a folder (with <code>Err</code> values sorted into the file list):</p>
  
  <pre><code>let (dir_list, file_list): (Vec&lt;std::io::Result&lt;DirEntry&gt;&gt;, Vec&lt;std::io::Result&lt;DirEntry&gt;&gt;) =
      dir_contents_iterator.partition(|entry_result| {
          match entry_result {
              Ok(entry) =&gt; {
                  entry
                      .file_type()
                      .and_then(|file_type| Ok(file_type.is_dir()))
                      .unwrap_or(false)
              },
              Err(_) =&gt; false
          }
      });
  </code></pre>
  
  <p>This code fails to compile with the following two errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
     --&gt; src/main.rs:179:13
      |
  179 |             Ok(entry) =&gt; {
      |             ^^^^^^^^^ expected reference, found enum `std::result::Result`
      |
      = note: expected type `&amp;std::result::Result&lt;std::fs::DirEntry, std::io::Error&gt;`
      = note:    found type `std::result::Result&lt;_, _&gt;`
  
  error[E0308]: mismatched types
     --&gt; src/main.rs:185:13
      |
  185 |             Err(_) =&gt; false
      |             ^^^^^^ expected reference, found enum `std::result::Result`
      |
      = note: expected type `&amp;std::result::Result&lt;std::fs::DirEntry, std::io::Error&gt;`
      = note:    found type `std::result::Result&lt;_, _&gt;`
  </code></pre>
  
  <p>I ended up solving my problem by rewriting my code to partition out the <code>Err</code> values first before partitioning between files and folders. This allows the match to be removed from the shown code and now it compiles. But for the sake of understanding, I'd still like to know why my original match's branch arms expect an <code>&amp;Result</code> reference rather than accepting a <code>Result</code>, especially in the case of the second branch arm (<code>Err(_) =&gt; false</code>) which doesn't even use the value!</p>
  
  <p><a href="https://github.com/starim/shadowhack/blob/sort-picker-by-filetype/src/main.rs#L177-L187" rel="nofollow noreferrer">Here's the problem code in the context of the project I'm working on</a> in case I've left out any details that help explain the problem.</p>