title: How do I get to a value held by Box in pattern matching?
body: <p>In trying to recall what I learnt last night from the third chapter of Rust By Example I've created an <code>enum</code> linked-list type this way:</p>
  <pre class="lang-rust prettyprint-override"><code>#[derive(Debug)]
  enum List {
      Nil,
      Cons(i32, Box&lt;List&gt;),
  }
  </code></pre>
  <p>I've attempted attaching a <code>tail()</code> method to this type as follows:</p>
  <pre class="lang-rust prettyprint-override"><code>impl List {
      // unrelated code not shown
      
      fn tail(&amp;self) -&gt; Self {
          match *self {
              Self::Cons(_, ref tail) =&gt; tail,
              nil =&gt; nil,
          }
      }
  }
  </code></pre>
  <p>But I get the following compiler error:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; .\ee-enum-recall-linked-lists.rs:32:40
     |
  30 |     fn tail(&amp;self) -&gt; Self {
     |                       ---- expected `List` because of return type
  31 |         match *self {
  32 |             Self::Cons(_, ref tail) =&gt; tail,
     |                                        ^^^^ expected enum `List`, found `&amp;Box&lt;List&gt;`
     |
     = note:   expected enum `List`
             found reference `&amp;Box&lt;List&gt;`
  </code></pre>
  <p>Which is baffling, because some other code I'd written in this same style to attach a <code>length()</code> method worked, and made me believe that the variable <code>tail</code> there is actually of type <code>List</code>.</p>
  <pre class="lang-rust prettyprint-override"><code>impl List {
      // unrelated code not shown
  
      fn length(&amp;self) -&gt; i32 {
          match *self {
              Self::Cons(_, ref tail) =&gt;  1 + tail.length(),
              _ =&gt; 0,
          }
      }
  }
  </code></pre>
  <p>So, I'm wondering:</p>
  <ul>
  <li>What is the type of the value held by the variable <code>tail</code> there, really?</li>
  <li>Why does <code>tail.length()</code> work if <code>tail</code> isn't a <code>List</code>?</li>
  <li>How do I <em>match down</em> to the list contained in <code>tail</code>?</li>
  </ul>