title: Lifetime issues with a closure argument in Rust
body: <p>I'm getting an error when trying to use a closure that does exactly the same as the <code>print</code> function below (in ln.9)</p>
  
  <p>The error is the usual <code>borrowed value does not live long enough</code>. I've tried to replicate this in the <code>playground</code> but I can't. I'm certain that this is mainly because I don't really understand what's going on here so any help would be really appreciated.</p>
  
  <p>What I can't understand is what is the difference between calling the <code>print</code> function and calling the <code>check</code> closure. They have exactly the same signature and even the same body. </p>
  
  <p>How does the context in which they were created affect the borrow checker? What would be the solution to this?</p>
  
  <pre><code>extern crate typed_arena;
  use typed_arena::Arena;
  
  #[derive(Debug)]
  struct AstNode&lt;'a&gt; {
      name: &amp;'a str,
  }
  
  fn get_ast&lt;'a&gt;(path: &amp;str, arena: &amp;'a Arena&lt;AstNode&lt;'a&gt;&gt;) -&gt; &amp;'a AstNode&lt;'a&gt; {
     // ...
  }
  
  type CheckFn&lt;'a&gt; = dyn Fn(&amp;'a AstNode&lt;'a&gt;);
  
  fn print&lt;'a&gt;(root: &amp;'a AstNode&lt;'a&gt;) {
      println!("{:?}", root);
  }
  
  fn it_does_not_have_details_if_all_ok&lt;'a&gt;(file: &amp;str, check: Box&lt;CheckFn&lt;'a&gt;&gt;) {
      let arena = Arena::new();
      let a = &amp;arena;
      let root = get_ast(file, a);
      println!("{:?}", root);
      // Works
      print(root);
      // Produces an error
      check(root);
  }   
  </code></pre>
  
  <p>The error is:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0597]: `arena` does not live long enough
    --&gt; src/main.rs:21:14
     |
  21 |     let a = &amp;arena;
     |              ^^^^^ borrowed value does not live long enough
  ...
  28 | }   
     | - borrowed value only lives until here
     |
  note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:1...
    --&gt; src/main.rs:19:1
     |
  19 | fn it_does_not_have_details_if_all_ok&lt;'a&gt;(file: &amp;str, check: Box&lt;CheckFn&lt;'a&gt;&gt;) {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>