title: Why do Arc and Mutex allow me to change the value of an immutable variable?
body: <p>Take this example:    </p>
  
  <pre><code>fn main() {
      let dato = std::sync::Arc::new(std::sync::Mutex::new(1u8));
  
      for _ in 0..3 {
          let value = dato.clone();
  
          std::thread::spawn(move || {
              let v = value.lock().unwrap();
              *v += 1; // &lt;- Error
          });
      }
  
      std::thread::sleep(std::time::Duration::from_secs(1u64));
  
      println!("{:?}", dato);
  }
  </code></pre>
  
  <blockquote>
    <p>cannot borrow immutable local variable <code>v</code> as mutable</p>
  </blockquote>
  
  <p>I know that changing to <code>mut</code> works:</p>
  
  <pre><code>std::thread::spawn(move || {
      let mut v = value.lock().unwrap();
      *v += 1;
  });
  </code></pre>
  
  <p>but why does this work:</p>
  
  <pre><code>let value = dato.clone();
  
  std::thread::spawn(move || {
      *value.lock().unwrap() += 1;    
  });
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=401b3f61be43bb67ea30562ae568fc19&amp;version=stable&amp;backtrace=0" rel="noreferrer">playground</a></p>