title: Lifetime in impl does not match method in trait
body: <h1>Code</h1>
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6eeb0140ad49f1e5c99861473bf9f57e" rel="noreferrer">Playground</a> (Stable Rust 1.45.0, 2018 edition) No external crates needed for example.</p>
  <pre><code>type Error = Box&lt;dyn std::error::Error&gt;;
  type Result&lt;R=()&gt; = std::result::Result&lt;R, Error&gt;;
  
  struct Arena;
  
  pub trait AsSized&lt;'a&gt; {
      type AsSized: Sized + 'a;
  }
  impl&lt;'a, T: Sized + 'a&gt; AsSized&lt;'a&gt; for T {
      type AsSized = Self;
  }
  impl&lt;'a, T: AsSized&lt;'a&gt;&gt; AsSized&lt;'a&gt; for [T] {
      type AsSized = &amp;'a [T::AsSized];
  }
  
  pub trait Format&lt;T&gt;: Send + Sync
  where T: ?Sized
  {
      fn get_bytes&lt;'a&gt;(&amp;self, value: &amp;'a T, arena: &amp;'a Arena) -&gt; Result&lt;&amp;'a [u8]&gt;;
      fn get_value&lt;'a&gt;(&amp;self, bytes: &amp;'a [u8], arena: &amp;'a Arena) -&gt; Result&lt;T::AsSized&gt;
      where T: AsSized&lt;'a&gt;;
  }
  
  struct RawBytes;
  
  impl Format&lt;[u8]&gt; for RawBytes
  where [u8]: for&lt;'a&gt; AsSized&lt;'a, AsSized=&amp;'a [u8]&gt;
  {
      fn get_bytes&lt;'a&gt;(&amp;self, value: &amp;'a [u8], _arena: &amp;'a Arena) -&gt; Result&lt;&amp;'a [u8]&gt; {
          Ok(value)
      }
      fn get_value&lt;'a&gt;(&amp;self, bytes: &amp;'a [u8], arena: &amp;'a Arena) -&gt; Result&lt;&lt;[u8] as AsSized&lt;'a&gt;&gt;::AsSized&gt; {
          Ok(bytes)
      }
  }
  </code></pre>
  <h1>Issue</h1>
  <p>I'm getting a compiler error on the impl of <code>get_value</code> for <code>RawBytes</code>:</p>
  <pre><code>error[E0195]: lifetime parameters or bounds on method `get_value` do not match the trait declaration
  </code></pre>
  <p>I don't understand what the problem is. It seems like the lifetime specification is the same between both definitions. How do I write the impl of <code>get_value</code> for <code>RawBytes</code> so that it works?</p>
  <p>I would think that since <code>u8: Sized</code> then <code>&lt;u8 as AsSized&lt;'a&gt;&gt;::AsSized = u8</code> and then <code>&lt;[u8] as AsSized&lt;'a&gt;&gt;::AsSized = &amp;'a [u8]</code> but it seems like that isn't the case?</p>
  <h1>Background</h1>
  <p><code>Format</code> takes an arena based allocator and converts a slice of bytes to and from a complex type. I plan to write an adapter for various Serde formats. <code>RawBytes</code> is a trivial implementaiton of <code>Format</code> for a slice of bytes that just returns the original slice.</p>
  <p>Both methods of <code>Format</code> are allowed to return a value that borrows from the input value. The format itself may be shared between threads, so the lifetime of self is unrelated to the returned value.</p>
  <p>The purpose of <code>AsSized</code> is to allow dynamically sized types like <code>str</code> and <code>[u8]</code> to be used directly, but since dynamically sized types can't be returned directly, <code>AsSized</code> provides a sized equivalent for any type; dynamically sized types return a reference to the DST instead  (borrowed from the arena). Sized types like <code>u8</code> that can be returned directly have an <code>AsSized</code> type of self</p>
  <h1>Also tried</h1>
  <pre><code>fn get_value&lt;'a&gt;(&amp;self, bytes: &amp;'a [u8], arena: &amp;'a Arena) -&gt; Result&lt;'a [u8]&gt;
  </code></pre>
  <p>I tried simplifying the impl's <code>get_value</code> to just name the slice directly; rust then says that the impl for <code>get_value</code> is missing entirely.</p>
  <pre><code>fn get_value&lt;'a&gt;(&amp;self, bytes: &amp;'a [u8], arena: &amp;'a Arena) -&gt; Result&lt;&amp;'a [&lt;u8 as AsSized&lt;'a&gt;&gt;::AsSized]&gt;
  </code></pre>
  <p>This give the same &quot;lifetime parameters... do not match&quot; error.</p>