nikomatsakis/rust-redex — pull request #6 by anasazi (2014-05-06 00:21:08+00:00)
Title: Lifetime Parameter Variance

Sorry about the messy commit log. Rebase didn't cooperate very well.

A lifetime parameter on a struct must be accompanied by one of three variance declarations.
`co` for covariant parameters
`contra` for contravariant parameters
`in` for invariant parameters
The existing test structs were updated to fit this syntax (usually with `co`).

I extended the subtype relation to account for parameter variance.
I'm not entirely sure I have co/contravariant correct; it may be backwards.

I also added a check to make sure structure declarations have correct variances.
The check is rather simple: if a field of a struct A is another struct B (ls), then for every lifetime in (ls), the variance of that parameter of struct B must equal the variance of the actual lifetime present in the type.
Since we have no function types, I don't think it's possible to jump between covariant and contravariant.
We would need to update this if we add function types.