about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-04-16 21:41:26 +0200
committerGitHub <noreply@github.com>2024-04-16 21:41:26 +0200
commitf939d1ff4820844595d0f50f94038869f1445d08 (patch)
treeb5ce75ce5508e61f1dfdefcd56d58b39b271b6c9
parent183c706305d8c4e0ccb0967932381baf7e0c3611 (diff)
parent82e7773bc1ab8b89c7b8c0a107c1f5741fe0bf1e (diff)
downloadrust-f939d1ff4820844595d0f50f94038869f1445d08.tar.gz
rust-f939d1ff4820844595d0f50f94038869f1445d08.zip
Rollup merge of #123979 - oli-obk:define_opaque_types7, r=compiler-errors
Subtype predicates only exist on inference types, so we can allow them to register opaque types within them.

We were unable to come up with an example where this could be reached (subtype predicates with either side not being an infer var gets consumed during any `select_where_possible` invocation, of which we have a lot in typeck). To ensure we don't silently accept new behaviour in case we missed a situation where this could occur, I have added an assert that prevents opaque types from having their hidden type constrained.

r? `@compiler-errors`
-rw-r--r--compiler/rustc_infer/src/infer/mod.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs
index f3f214f2123..2963557bb3c 100644
--- a/compiler/rustc_infer/src/infer/mod.rs
+++ b/compiler/rustc_infer/src/infer/mod.rs
@@ -945,14 +945,27 @@ impl<'tcx> InferCtxt<'tcx> {
             (&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => {
                 return Err((a_vid, b_vid));
             }
+            // We don't silently want to constrain hidden types here, so we assert that either one side is
+            // an infer var, so it'll get constrained to whatever the other side is, or there are no opaque
+            // types involved.
+            // We don't expect this to actually get hit, but if it does, we now at least know how to write
+            // a test for it.
+            (_, ty::Infer(ty::TyVar(_))) => {}
+            (ty::Infer(ty::TyVar(_)), _) => {}
+            _ if (r_a, r_b).has_opaque_types() => {
+                span_bug!(
+                    cause.span(),
+                    "opaque types got hidden types registered from within subtype predicate: {r_a:?} vs {r_b:?}"
+                )
+            }
             _ => {}
         }
 
         self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
             if a_is_expected {
-                Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
+                Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
             } else {
-                Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
+                Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a))
             }
         })
     }