title: Why am I allowed to have multiple &mut refs in nested functions (Rust)?
body: <p>I'm new to rust, and am wondering why the following code doesn't result in a:
  <em>cannot borrow val as mutable more than once at a time</em> error.  It seems like by the time I've reached the <code>second_layer</code> function, I should have three separate references to the same original <code>val</code> variable:</p>
  <p><code>val_ref</code> in the main function body</p>
  <p><code>val_ref2</code> in the first_layer function body</p>
  <p><code>val_ref3</code> in the second_layer function body</p>
  <p>Any help would be appreciated!</p>
  <pre><code>fn first_layer(val_ref2: &amp;mut String)
  {
      *val_ref2 = String::from(&quot;first_layer&quot;);
      println!(&quot;{}&quot;, val_ref2);
      second_layer(val_ref2);
  }
  
  fn second_layer(val_ref3: &amp;mut String)
  {
      *val_ref3 = String::from(&quot;second_layer&quot;);
      println!(&quot;{}&quot;, val_ref3);
  
  }
  
  fn main()
  {
      let mut val = String::from(&quot;asdf&quot;);
      let val_ref: &amp;mut String = &amp;mut val;
  
      first_layer(val_ref);
  
      println!(&quot;{}&quot;, val_ref);
  
  }
  </code></pre>
  <p>Thanks,</p>