title: Argument requires that _ is borrowed for 'static - how do I work round this?
body: <p>I have a lifetime/borrowing error from the Rust compiler that I can't get my head around. The problem seems to be that Rust assumes that when an argument is passed to a function that returns a reference to a static value, the argument reference must also be static. </p>
  
  <pre class="lang-rust prettyprint-override"><code>#[derive(Debug)]
  struct TestThingy&lt;'a&gt; {
      label: &amp;'a str,
  }
  
  const TEST_VALUES: [TestThingy; 3] = [
      TestThingy { label: "one" },
      TestThingy { label: "two" },
      TestThingy { label: "three" },
  ];
  
  pub fn value_for_num(num: &amp;str) -&gt; Option&lt;&amp;'static TestThingy&gt; {
      TEST_VALUES.iter().find(|value| value.label == num)
  }
  
  pub fn test_out_thingy() {
      let tmp_val = String::from("two");
      if let Some(test_thingy) = value_for_num(&amp;tmp_val) {
          println!("test_thingy: {:?}", test_thingy);
      }
  }
  
  fn main() {
      test_out_thingy();
  }
  </code></pre>
  
  <p>Rust errors with: <code>error[E0597]: `tmp_val` does not live long enough</code> - E0597 refers to when a value gets dropped whilst its still borrowed, which isn't happening here - I don't know how to convince Rust of that though.</p>
  
  <p>The idea behind this code, for more context, is it's a lookup mechanism for compile-time/static config (in my codebase they are <code>Syntax</code> values, matched on the basis of a provided filename <code>&amp;str</code>). So the provided argument genuinely does not live as long as the static config, but I don't understand why that's a problem. The returned value doesn't/can't contain the argument as a reference, so I'm super unclear why this borrowing error is happening.</p>