<p dir="auto">I wanted to wrap the OpenGL API to create a safer interface. Like many other APIs the OpenGL API gives away integer tokens representing created objects. For example, the call glCreateProgram creates a GLuint token representing a shader program object. These tokens in the OpenGL API (and other similar APIs) are basically the same idea as pointer types. Because these tokens behave similarly to pointers I would like to wrap them in a type which has similar behaviours. For example, the glGetAttribLocation call gets a token representing an attribute, or buffer to fill with data of a shader program. I would like to wrap the token returned by glGetAttribLocation in a structure which has the same lifetime as the program token returned by glCreateProgram, but to do this I have to use an unneeded amount of pointers (to get proper lifetime guarantees.) Basically, I would like my wrapped glGetAttribLocation call to be like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" impl GLContext {
  fn get_attrib_location &lt;'r&gt; (
     &amp;self,
     program: Program &lt;'r&gt;,
     name: ~str
  ) -&gt; Option &lt;AttributeLocation &lt;'r&gt;&gt; { /* Definition Omitted */ }"><pre class="notranslate"><code class="notranslate"> impl GLContext {
  fn get_attrib_location &lt;'r&gt; (
     &amp;self,
     program: Program &lt;'r&gt;,
     name: ~str
  ) -&gt; Option &lt;AttributeLocation &lt;'r&gt;&gt; { /* Definition Omitted */ }
</code></pre></div>
<p dir="auto">Instead of:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" impl GLContext {
  fn get_attrib_location &lt;'r&gt; (
     &amp;self,
     program: &amp;'r Program,
     name: ~str
  ) -&gt; Option &lt;AttributeLocation &lt;'r&gt;&gt; { /* Definition Omitted */ }"><pre class="notranslate"><code class="notranslate"> impl GLContext {
  fn get_attrib_location &lt;'r&gt; (
     &amp;self,
     program: &amp;'r Program,
     name: ~str
  ) -&gt; Option &lt;AttributeLocation &lt;'r&gt;&gt; { /* Definition Omitted */ }
</code></pre></div>
<p dir="auto"><strong>UPDATE:</strong> Updating this issue to reflect current thinking, which is that inference should issue a warning when a lifetime parameter is inferred to be bivariant (which implies that the parameter is unused).</p>
<p dir="auto"><strong>ORIGINAL:</strong> It's sometimes necessary to specify a lifetime on an object that <em>doesn't</em> contain borrowed pointers, because lifetime dependencies can be required for safety outside of Rust's borrowed pointer system. A dummy borrowed pointer member is a workaround, but wasteful.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nikomatsakis/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nikomatsakis">@nikomatsakis</a></p>