diff options
| author | bors <bors@rust-lang.org> | 2022-09-27 10:45:57 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-27 10:45:57 +0000 | 
| commit | 57ee5cf5a93923dae9c98bffb11545fc3a31368d (patch) | |
| tree | abd98065e805dca388767b651ae60673397fea9d /compiler/rustc_hir_analysis/src/variance/xform.rs | |
| parent | d9297d22ad9edc2b56f0dd8734c1187a0c88be69 (diff) | |
| parent | 1fc86a63f451b81606e4787692517dc613f333db (diff) | |
| download | rust-57ee5cf5a93923dae9c98bffb11545fc3a31368d.tar.gz rust-57ee5cf5a93923dae9c98bffb11545fc3a31368d.zip | |
Auto merge of #102306 - lcnr:rustc_hir_analysis, r=compiler-errors
rename rustc_typeck to rustc_hir_analysis first part of https://github.com/rust-lang/compiler-team/issues/529 r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_hir_analysis/src/variance/xform.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/variance/xform.rs | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/compiler/rustc_hir_analysis/src/variance/xform.rs b/compiler/rustc_hir_analysis/src/variance/xform.rs new file mode 100644 index 00000000000..027f0859fcd --- /dev/null +++ b/compiler/rustc_hir_analysis/src/variance/xform.rs @@ -0,0 +1,22 @@ +use rustc_middle::ty; + +pub fn glb(v1: ty::Variance, v2: ty::Variance) -> ty::Variance { + // Greatest lower bound of the variance lattice as + // defined in The Paper: + // + // * + // - + + // o + match (v1, v2) { + (ty::Invariant, _) | (_, ty::Invariant) => ty::Invariant, + + (ty::Covariant, ty::Contravariant) => ty::Invariant, + (ty::Contravariant, ty::Covariant) => ty::Invariant, + + (ty::Covariant, ty::Covariant) => ty::Covariant, + + (ty::Contravariant, ty::Contravariant) => ty::Contravariant, + + (x, ty::Bivariant) | (ty::Bivariant, x) => x, + } +} | 
