Pre-RFC: Require explicit markers for unused type/lifetime parameters

This is a "pre-RFC" for requiring explicit markers for unused type/lifetime parameters:

It supercedes my prior attempt:

cc @pnkfelix

1 Like

Of course the particular use case that you use in demonstration would also be handled by allowing lifetimes on unsafe pointers. :wink:

(But I will assume there will always be motivations for shadow parameters, regardless of what other language changes are made.)

I think something like this is a good idea and makes writing unsafe code (such as for struct Items) less error-prone.

But I think variance/subtyping for lifetimes should be revisited again. Aaron Turon (@aturon) opened an issue to that effect already (which went nowhere). But I think I can provide an additional argument to that discussion that might convince somebody. In fact, I talked to Eduard Burtescu (@eddyb) on IRC about it and he suggested that I should add a comment here @nikomatsakis .

The argument goes as follows: In type bounds for generics C: T can be considered something like a subtyping relation (C implements T --> C is sort of a subtype of an abstract T). We have something like this for lifetimes as well: 'a: 'b and it means “The lifetime a is NOT shorter than the lifetime b. Or: C: 'static meaning the lifetime of C is NOT less than static. With references we have a similar relationship. If a function takes a reference of type &'b T we can pass it a reference of type &'a T where just like above the lifetime 'a is NOT less than the lifetime 'b. This makes &'a T a subtype of &'b T. But for some reason references are currently considered contravariant w.r.t. lifetimes. This in turn implies that the sub"typing” relation for lifetimes is backwards and inconsistent to the 'a: 'b syntax. So, the lifetime bound 'a: 'b actually corresponds to 'b <: 'a with the current definition of sub"typing" for lifetimes.

I think it’s a good idea to define 'a <: 'b to mean the same thing as 'a: 'b (lifetime a is NOT less than lifetime b) and consider references to be covariant w.r.t. lifetimes. And if you think about it, it makes sense. Types that are 'static are just a subset of all types as opposed to all types being a subset of static types.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.