title: How to work around a HRTB bug?
body: <p>This snippet does not compile because of a <a href="https://github.com/rust-lang/rust/issues/27863" rel="nofollow noreferrer">compiler bug</a>:</p>
  
  <pre><code>struct Theory&lt;'a, T: 'a&gt; {
      left: &amp;'a T,
  }
  
  pub struct Contain&lt;'a, T: 'a, U&gt;
  where
      &amp;'a T: IntoIterator,
      for&lt;'x&gt; &lt;(&amp;'a T) as IntoIterator&gt;::Item: PartialEq&lt;&amp;'x U&gt;,
  {
      theory: Theory&lt;'a, T&gt;,
      right: U,
  }
  
  impl&lt;'a, T: 'a, U&gt; Drop for Contain&lt;'a, T, U&gt;
  where
      &amp;'a T: IntoIterator,
      for&lt;'x&gt; &lt;(&amp;'a T) as IntoIterator&gt;::Item: PartialEq&lt;&amp;'x U&gt;,
  {
      fn drop(&amp;mut self) {
          //TODO
      }
  }
  
  fn main() {}
  </code></pre>
  
  <p>I need this because I must compare the iterator <code>Item</code>s with <code>U</code>; but <code>Item</code> is a reference type, because I call <code>into_iter()</code> in a borrowed collection.</p>
  
  <p>I then tried something like this to work around:</p>
  
  <pre><code>struct Theory&lt;'a, T: 'a&gt; {
      left: &amp;'a T,
  }
  
  pub struct Contain&lt;'a, 'b: 'a, T: 'a, U: 'b&gt;
  where
      &amp;'a T: IntoIterator,
      &lt;(&amp;'a T) as IntoIterator&gt;::Item: PartialEq&lt;&amp;'b U&gt;,
  {
      theory: Theory&lt;'a, T&gt;,
      right: U,
      _marker: ::std::marker::PhantomData&lt;&amp;'b ()&gt;,
  }
  
  impl&lt;'a, 'b, T: 'a, U&gt; Drop for Contain&lt;'a, 'b, T, U&gt;
  where
      &amp;'a T: IntoIterator,
      &lt;(&amp;'a T) as IntoIterator&gt;::Item: PartialEq&lt;&amp;'b U&gt;,
  {
      fn drop(&amp;mut self) {
          for left in self.theory.left.into_iter() {
              if left == &amp;self.right {
                  return;
              }
          }
          //handle case where all lefts are different of right
      }
  }
  
  fn main() {}
  </code></pre>
  
  <p>But I got a:</p>
  
  <pre><code>cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
    --&gt; src/main.rs:22:24
     |
  22 |             if left == &amp;self.right {
     |                        ^^^^^^^^^^^
     |
  </code></pre>
  
  <p>How can I iterate over <code>left</code>, then compare each elements with <code>right</code>?</p>