title: Rust book Listing 10-15:when i use 'let largest = item', the 'largest' can't be changed
body: <p>I'm learning Rust by the rust book.But when I try the <a href="https://doc.rust-lang.org/book/ch10-02-traits.html#fixing-the-largest-function-with-trait-bounds" rel="nofollow noreferrer">Listing 10-15</a>, I found I can't change the value of 'largest' by using 'let'. The introduction of the topic is</p>
  <blockquote>
  <p>Another way we could implement largest is for the function to return a reference to a T value in the slice. If we change the return type to &amp;T instead of T, thereby changing the body of the function to return a reference, we wouldn’t need the Clone or Copy trait bounds and we could avoid heap allocations. Try implementing these alternate solutions on your own!</p>
  </blockquote>
  <p>My code is:</p>
  <pre><code>fn largest&lt;T&gt;(list: &amp;[T]) -&gt; &amp;T
      where T: PartialOrd + Copy
  {
      let largest = &amp;list[0];
  
      for item in list.iter() {
          if item &gt; largest {
              let largest = item;
          }
      }
      return largest
  }
  
  
  fn main() {
      let number_list = vec![34.0, 50.2, 25.32, 100.32, 65.32, 100.33];
      let result = largest(&amp;number_list);
      println!(&quot;The largest number is {}&quot;, result);
  
      let char_list = vec!['y', 'm', 'a', 'q'];
      let result = largest(&amp;char_list);
      println!(&quot;The largest char is {}&quot;, result);
  }
  </code></pre>
  <p>I get 1 warning:</p>
  <pre><code>warning: unused variable: `largest`
   --&gt; src/main.rs:8:17
    |
  8 |             let largest = item;
    |                 ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_largest`
    |
    = note: `#[warn(unused_variables)]` on by default
  
  warning: 1 warning emitted
  </code></pre>
  <p>And the result is not right:</p>
  <pre><code>The largest number is 34
  The largest char is y
  </code></pre>