title: Why are "&str" and "&String" treated as references to the same value?
body: <p>A beginner of rust. After I read chapter 4.3, I have confusion about the content of chapter 4.3 which has a cross-reference to the principle</p>
  <blockquote>
  <p>At any given time, you can have either one mutable reference or any number of immutable references.</p>
  </blockquote>
  <p>The simplified example is</p>
  <pre class="lang-rust prettyprint-override"><code>fn main() {
      let mut str: String = String::from(&quot;hello&quot;);
      let slice: &amp;str = &amp;str[0..2]; // #1
      str.clear(); // #2
      println!(&quot;{}&quot;, slice);
  }
  </code></pre>
  <p>This example results in a panic error when compiling it. The tutorial annotation says the reason is that it violates the principle above. However, I cannot understand it. In my mind, <code>#1</code> creates an immutable reference with the type <strong>&amp;str</strong>, instead, <code>#2</code> makes a mutable reference with type <strong>&amp;String</strong>, according to the type, they seem not to refer to the same things, since they have different reference types. Why does it violate the principle above that seems to only apply to the reference with the same type? Is there any principle that can clarify this issue?</p>