From 20431706a863f92cb37dc512fef6e48d192aaf2c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:38 +0200 Subject: Merging upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_hir_analysis/src/variance/xform.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 compiler/rustc_hir_analysis/src/variance/xform.rs (limited to 'compiler/rustc_hir_analysis/src/variance/xform.rs') 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 000000000..027f0859f --- /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, + } +} -- cgit v1.2.3