title: Rust `From` trait, errors, reference vs Box and `?` operator
body: <p>I am pretty confused on the <code>?</code> operator in functions that return <code>Result&lt;T, E&gt;</code>.</p>
  
  <p>I have the following snippet of code:</p>
  
  <pre><code>use std::error;
  use std::fs;
  
  
  fn foo(s: &amp;str) -&gt; Result&lt;&amp;str, Box&lt;error::Error&gt;&gt; {
      let result = fs::read_to_string(s)?;
      return Ok(&amp;result);
  }
  
  fn bar(s: &amp;str) -&gt; Result&lt;&amp;str, &amp;dyn error::Error&gt; {
      // the trait `std::convert::From&lt;std::io::Error&gt;` is not implemented for `&amp;dyn std::error::Error` (1)
      let result = fs::read_to_string(s)?;
      return Ok(&amp;result);
  }
  
  fn main() {
      println!("{}", foo("foo.txt").unwrap());
      println!("{}", bar("bar.txt").unwrap());
  }
  </code></pre>
  
  <p>As you might see from the above snippet, the <code>?</code> operator works pretty well with the returned boxed error, but not with dynamic error references (error at <code>(1)</code>).</p>
  
  <p>Is there any specific reason why it does not work? In my limited knowledge of Rust, it is more natural to return an error reference, rather than a boxed object: in the end, after returning rom the <code>foo</code> function, I expect deref coercion to work with it, so why not returning the error reference itself?</p>