]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/infer/at.rs
port the relate-types code from NLL type-check into a type-op
[rust.git] / src / librustc / infer / at.rs
index 89dbc76c8a65c2b58306e8d3ea1d95f2de912d29..0e4c94aaaf3942e31755f00f6eb8d13b90e23491 100644 (file)
@@ -142,6 +142,28 @@ pub fn eq<T>(self,
         self.trace(expected, actual).eq(&expected, &actual)
     }
 
+    pub fn relate<T>(
+        self,
+        expected: T,
+        variance: ty::Variance,
+        actual: T,
+    ) -> InferResult<'tcx, ()>
+        where T: ToTrace<'tcx>
+    {
+        match variance {
+            ty::Variance::Covariant => self.sub(expected, actual),
+            ty::Variance::Invariant => self.eq(expected, actual),
+            ty::Variance::Contravariant => self.sup(expected, actual),
+
+            // We could make this make sense but it's not readily
+            // exposed and I don't feel like dealing with it. Note
+            // that bivariance in general does a bit more than just
+            // *nothing*, it checks that the types are the same
+            // "modulo variance" basically.
+            ty::Variance::Bivariant => panic!("Bivariant given to `relate()`"),
+        }
+    }
+
     /// Compute the least-upper-bound, or mutual supertype, of two
     /// values. The order of the arguments doesn't matter, but since
     /// this can result in an error (e.g., if asked to compute LUB of