title: Lifetime of references passed to function stops subsequent access
body: <p>I would like to be able to pass mutable objects by reference to a function to have it 'work on them' but am struggling. I tried <s>all</s> most feasible combinations of lifetimes in the function definition and this seemed to be the only one to compile (but missed the correct one pointed out below). I suspect I need to use a Rust 'wrapper' but can't find any examples of what I would think was a very standard thing to do.</p>
  
  <pre><code>fn add&lt;'a&gt;(vec: &amp;'a mut Vec&lt;&amp;'a str&gt;, txt: &amp;'a str) {
      vec.push(txt);
      for t in vec.iter() {
          print!("{} ", t);
      }
  }
  
  fn main() {
      let mut st = vec!["hello"];
      let words = vec!["world", "again", "!"];
      //for txt in words.iter() { // what I wanted to do
      //  add(&amp;mut st, txt);
      //}
      st.push(","); // experiment works
      st.push("cruel");
      {
          add(&amp;mut st, words[0]); // but this borrows to the end of main(){}
      } // instead of here
        // add(&amp;mut st, words[1]); // so, for instance, this is a second borrow and not allowed
  }
  </code></pre>
  
  <p>EDIT - answered as below in comments.</p>
  
  <p>Thank you so much @Shepmaster and @trentcl, I had been singing the praises of the explicit and helpful rust debugger messages but failed to read</p>
  
  <pre><code>error[E0623]: lifetime mismatch
   --&gt; src/main.rs:3:12
    |
  2 | fn add(vec: &amp;mut Vec&lt;&amp;str&gt;, txt: &amp;str) {
    |                      ----        ---- these two types are declared with different lifetimes...
  3 |   vec.push(txt);
    |            ^^^ ...but data from `txt` flows into `vec` here
  </code></pre>
  
  <p>When I first added the lifetime specs. I put them in initially for the two main arguments and only added the &lt;&amp;str> when I got a further error. As you say it should be done like this:</p>
  
  <pre><code>fn add&lt;'a&gt;(vec: &amp;mut Vec&lt;&amp;'a str&gt;, txt: &amp;'a str) {
    vec.push(txt);
  }
  
  fn main() {
    let mut st = vec!["hello"];
    let words = vec!["world", "again", "!"];
    for txt in words.iter() { // what I wanted to do
      add(&amp;mut st, txt);
    }
    for txt in st.iter() {
      print!("{} ", txt);
    }
  }
  </code></pre>