title: Rust: borrow checker in infinite loop
body: <p>I'm currently building an application with a main loop. Settings are added to the struct as references to avoid boxing. The problem is, even though it seems perfectly valid, the borrow checker does not validate infinite loops. As an example, this does not compile:</p>
  
  <pre><code>struct Demo&lt;'a&gt; {
      data: Vec&lt;&amp;'a u8&gt;,
  }
  
  impl&lt;'a&gt; Demo&lt;'a&gt; {
      fn new(data: Vec&lt;&amp;'a u8&gt;) -&gt; Self {
          Demo { data }
      }
  
      fn bug(mut self) -&gt; ! {
          let a = 8;
          {
              self.data.push(&amp;a);
              {
                  self.forever();
              }
          }
      }
  
      fn forever(self) -&gt; ! {
          loop {
              for dat in &amp;self.data {
                  println!("{}", dat);
              }
          }
      }
  }
  
  fn main() {
      let v = vec![&amp;1, &amp;1, &amp;2, &amp;3];
      Demo::new(v).bug();
  }
  </code></pre>
  
  <p>My question is: how could I refactor the code above to avoid boxing the data, but still being able to use a main loop.</p>