title: Why can impl trait not be used to return multiple / conditional types?
body: <p>I'm trying to get a random number generator. Since <code>OsRng::new()</code> can fail, I'd like to fall back to <code>thread_rng()</code> if I have to:</p>
  <pre><code>extern crate rand; // 0.5.5
  
  use rand::{thread_rng, OsRng, RngCore};
  
  fn rng() -&gt; impl RngCore
  {
      match OsRng::new() {
          Ok(rng) =&gt; rng,
          Err(e) =&gt; thread_rng()
      }
  }
  </code></pre>
  <p>However, I get this error message which I cannot understand:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0308]: match arms have incompatible types
   --&gt; src/lib.rs:6:5
    |
  6 | /     match OsRng::new() {
  7 | |         Ok(rng) =&gt; rng,
  8 | |         Err(e) =&gt; thread_rng(),
    | |                   ------------ match arm with an incompatible type
  9 | |     }
    | |_____^ expected struct `rand::OsRng`, found struct `rand::ThreadRng`
    |
    = note: expected type `rand::OsRng`
               found type `rand::ThreadRng`
  </code></pre>
  <p>Why is the compiler expecting <code>rand::OsRng</code> here instead of an implementation of <code>RngCore</code>? If I remove the <code>match</code> and directly return <code>thread_rng()</code>, I don't get above error message.</p>
  <p>I do not believe that this is a duplicate of <a href="https://stackoverflow.com/q/30661046/3755692">How do I return an instance of a trait from a method?</a>, as the other question is asking about <strong>how</strong> one can return a trait from a function, and this question is about <strong>why</strong> the compiler will not allow me to return a trait but wants me to return an <code>OsRng</code> which is not the return type of the function.</p>