title: Ownership of values whose variables are shadowed
body: <p>See some code below:</p>
  <pre><code>#[derive(Debug)]
  struct MyString {
      a: String,
  }
  
  impl MyString {
      fn new(s: &amp;str) -&gt; Self {
          MyString { a: String::from(s) }
      }
  }
  
  impl Deref for MyString {
      type Target = String;
  
      fn deref(&amp;self) -&gt; &amp;Self::Target {
          &amp;self.a
      }
  }
  
  impl Drop for MyString {
      fn drop(&amp;mut self) {
          println!(&quot;{} dropped!&quot;, self.a);
      }
  }
  
  fn main() {
      let mut test1 = MyString::new(&quot;test1&quot;);
      let mut test1 = MyString::new(&amp;test1);
      println!(&quot;shadow variable test1&quot;);
      test1.a = String::from(&quot;test2&quot;);
  }
  </code></pre>
  <p>I thought there should be a compile error because test1 is still borrowed.</p>
  <p>However, there's no compile error, and the result is</p>
  <pre><code>shadow variables test1
  test2 dropped
  test1 dropped
  </code></pre>
  <p>So if a variable is shadowed, the value is still valid in the current scope.
  But who is its owner?</p>