title: Do Rust lifetimes influence the semantics of the compiled program?
body: <p>I'm trying to grok lifetimes in Rust and asked myself whether they are "just" a safety measure (and a way to communicate how safety is ensured, or not, in the case of errors) or if there are cases where different choices of lifetimes actually change how the program runs, i.e. whether lifetimes make a semantic difference to the compiled program.</p>
  
  <p>And with "lifetimes" I refer to all the pesky little <code>'a</code>, <code>'b</code>, <code>'static</code> markers we include to make the borrow checker happy. Of course, writing </p>
  
  <pre><code>{
      let foo = File::open("foo.txt")?;
  } 
  foo.write_all(b"bar");
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>let foo = File::open("foo.txt")?;
  foo.write_all(b"bar");
  </code></pre>
  
  <p>will close the file descriptor before the write occurs, even if we could access foo afterwards, but that kind of scoping and destructor-calling also happens in C++.</p>