about summary refs log tree commit diff
path: root/compiler/rustc_infer/src
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2022-11-14 17:42:46 +0100
committerlcnr <rust@lcnr.de>2022-11-15 13:34:08 +0100
commit45f441a7b41d09bb78b0ba3e260d2c868ef6add7 (patch)
tree0ab27b9bde513532c7f3b006f74148a246e85ad1 /compiler/rustc_infer/src
parentca92d90b5917e7176d5ff06607a2cd5352c088d3 (diff)
downloadrust-45f441a7b41d09bb78b0ba3e260d2c868ef6add7.tar.gz
rust-45f441a7b41d09bb78b0ba3e260d2c868ef6add7.zip
nll: correctly deal with bivariance
Diffstat (limited to 'compiler/rustc_infer/src')
-rw-r--r--compiler/rustc_infer/src/infer/nll_relate/mod.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs
index 600f94f095e..74b2fb613b7 100644
--- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs
+++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs
@@ -556,8 +556,12 @@ where
         self.ambient_variance_info = self.ambient_variance_info.xform(info);
 
         debug!(?self.ambient_variance);
-
-        let r = self.relate(a, b)?;
+        // In a bivariant context this always succeeds.
+        let r = if self.ambient_variance == ty::Variance::Bivariant {
+            a
+        } else {
+            self.relate(a, b)?
+        };
 
         self.ambient_variance = old_ambient_variance;