about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/infer/combine.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-19 02:17:44 +0000
committerMichael Goulet <michael@errs.io>2023-03-19 03:45:47 +0000
commit322c7b6269f0a2147b85f4cc38006afca22a0d31 (patch)
tree01d060e004b85930177f80177bfaf5d542821fb2 /compiler/rustc_infer/src/infer/combine.rs
parentab9bb3ea368b2412531a3e8c07ba73d1dd690134 (diff)
downloadrust-322c7b6269f0a2147b85f4cc38006afca22a0d31.tar.gz
rust-322c7b6269f0a2147b85f4cc38006afca22a0d31.zip
Constrain const vars to error if const types are mismatched
Diffstat (limited to 'compiler/rustc_infer/src/infer/combine.rs')
-rw-r--r--compiler/rustc_infer/src/infer/combine.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs
index bb6fdd2ffc2..4503af03ca3 100644
--- a/compiler/rustc_infer/src/infer/combine.rs
+++ b/compiler/rustc_infer/src/infer/combine.rs
@@ -189,10 +189,19 @@ impl<'tcx> InferCtxt<'tcx> {
         // the expected const's type. Specifically, we don't want const infer vars
         // to do any type shapeshifting before and after resolution.
         if let Err(guar) = compatible_types {
-            return Ok(self.tcx.const_error_with_guaranteed(
-                if relation.a_is_expected() { a.ty() } else { b.ty() },
-                guar,
-            ));
+            // HACK: equating both sides with `[const error]` eagerly prevents us
+            // from leaving unconstrained inference vars during things like impl
+            // matching in the solver.
+            let a_error = self.tcx.const_error_with_guaranteed(a.ty(), guar);
+            if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
+                return self.unify_const_variable(vid, a_error);
+            }
+            let b_error = self.tcx.const_error_with_guaranteed(b.ty(), guar);
+            if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
+                return self.unify_const_variable(vid, b_error);
+            }
+
+            return Ok(if relation.a_is_expected() { a_error } else { b_error });
         }
 
         match (a.kind(), b.kind()) {