title: Why does taking a static reference to a const return a reference to a temporary variable?
body: <p>In Rust I have the following code:</p>
  
  <pre><code>pub trait Test: Sized {
      const CONST: Self;
      fn static_ref() -&gt; &amp;'static Self {
          &amp;Self::CONST
      }
  }
  </code></pre>
  
  <p>My expectation is that since <code>const</code> is <code>'static</code>, then I should be able to take a reference to it that is also <code>'static</code>. However, the compiler gives the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0515]: cannot return reference to temporary value
     --&gt; file.rs:9:9
      |
    9 |         &amp;Self::CONST
      |         ^-----------
      |         ||
      |         |temporary value created here
      |         returns a reference to data owned by the current function
  </code></pre>
  
  <p>How is a temporary variable being introduced here?</p>
  
  <p>Additionally, it seems that there are some cases where taking a reference to a constant does work. Here is a short concrete example with a slightly different implementation of Test</p>
  
  <pre><code>pub trait Test: Sized {
      fn static_ref() -&gt; &amp;'static Self;
  }
  
  struct X;
  
  impl Test for X {
      fn static_ref() -&gt; &amp;'static Self {
          &amp;X
      }
  }
  </code></pre>