]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_hir_analysis/src/variance/xform.rs
Rollup merge of #107058 - clubby789:eqeq-homoglyph, r=wesleywiser
[rust.git] / compiler / rustc_hir_analysis / src / variance / xform.rs
1 use rustc_middle::ty;
2
3 pub fn glb(v1: ty::Variance, v2: ty::Variance) -> ty::Variance {
4     // Greatest lower bound of the variance lattice as
5     // defined in The Paper:
6     //
7     //       *
8     //    -     +
9     //       o
10     match (v1, v2) {
11         (ty::Invariant, _) | (_, ty::Invariant) => ty::Invariant,
12
13         (ty::Covariant, ty::Contravariant) => ty::Invariant,
14         (ty::Contravariant, ty::Covariant) => ty::Invariant,
15
16         (ty::Covariant, ty::Covariant) => ty::Covariant,
17
18         (ty::Contravariant, ty::Contravariant) => ty::Contravariant,
19
20         (x, ty::Bivariant) | (ty::Bivariant, x) => x,
21     }
22 }