title: Specifying lifetimes in function pointer types in a struct
body: <p>I have a function <code>foo</code> defined as follows:</p>
  
  <pre><code>fn foo&lt;'a&gt;(a: &amp;'a i32, b: &amp;i32) -&gt; &amp;'a i32 { a }
  </code></pre>
  
  <p>I want to store  a pointer to that function in a struct:</p>
  
  <pre><code>struct S {
      f: fn(a: &amp;i32, b: &amp;i32) -&gt; &amp;i32,
  }
  </code></pre>
  
  <p>Because there are two input lifetimes, the result lifetime cannot be inferred:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0106]: missing lifetime specifier
    |
  2 |     f: fn(a: &amp;i32, b: &amp;i32) -&gt; &amp;i32,
    |                                ^ expected lifetime parameter
    |
    = help: this function's return type contains a borrowed value,
      but the signature does not say whether it is borrowed from a or b
  </code></pre>
  
  <p>When I ask the compiler for <code>foo</code>'s type, it's not very helpful either:</p>
  
  <pre><code>let () = foo;
  </code></pre>
  
  <p>gives me</p>
  
  <pre class="lang-none prettyprint-override"><code>expected type `fn(&amp;'a i32, &amp;i32) -&gt; &amp;'a i32 {foo}`
  </code></pre>
  
  <p>which obviously doesn't work because <code>'a</code> is not defined anywhere. </p>
  
  <p>So how do I declare a lifetime in this context? Trying one of</p>
  
  <pre><code>f: fn&lt;'a&gt;(a: &amp;'a i32, b: &amp;i32) -&gt; &amp;'a i32
  f&lt;'a&gt;: fn(a: &amp;'a i32, b: &amp;i32) -&gt; &amp;'a i32
  </code></pre>
  
  <p>results in a syntax error, and I could not find documentation covering this specific situation.</p>