1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 fn xform(self, v: Self) -> Self;
17 impl Xform for ty::Variance {
18 fn xform(self, v: ty::Variance) -> ty::Variance {
19 // "Variance transformation", Figure 1 of The Paper
21 // Figure 1, column 1.
22 (ty::Covariant, ty::Covariant) => ty::Covariant,
23 (ty::Covariant, ty::Contravariant) => ty::Contravariant,
24 (ty::Covariant, ty::Invariant) => ty::Invariant,
25 (ty::Covariant, ty::Bivariant) => ty::Bivariant,
27 // Figure 1, column 2.
28 (ty::Contravariant, ty::Covariant) => ty::Contravariant,
29 (ty::Contravariant, ty::Contravariant) => ty::Covariant,
30 (ty::Contravariant, ty::Invariant) => ty::Invariant,
31 (ty::Contravariant, ty::Bivariant) => ty::Bivariant,
33 // Figure 1, column 3.
34 (ty::Invariant, _) => ty::Invariant,
36 // Figure 1, column 4.
37 (ty::Bivariant, _) => ty::Bivariant,
42 pub fn glb(v1: ty::Variance, v2: ty::Variance) -> ty::Variance {
43 // Greatest lower bound of the variance lattice as
44 // defined in The Paper:
50 (ty::Invariant, _) | (_, ty::Invariant) => ty::Invariant,
52 (ty::Covariant, ty::Contravariant) => ty::Invariant,
53 (ty::Contravariant, ty::Covariant) => ty::Invariant,
55 (ty::Covariant, ty::Covariant) => ty::Covariant,
57 (ty::Contravariant, ty::Contravariant) => ty::Contravariant,
59 (x, ty::Bivariant) | (ty::Bivariant, x) => x,