about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/solve/mod.rs
diff options
context:
space:
mode:
authorBoxy <supbscripter@gmail.com>2024-05-29 17:06:50 +0100
committerBoxy <supbscripter@gmail.com>2024-05-29 17:06:54 +0100
commitd5bd4e233d2bb4415138e384e66379eedbc7e76e (patch)
tree48097f82d6b2ccf2d0f8aec6744f377d16f2bd06 /compiler/rustc_trait_selection/src/solve/mod.rs
parentda159eb331b27df528185c616b394bb0e1d2a4bd (diff)
downloadrust-d5bd4e233d2bb4415138e384e66379eedbc7e76e.tar.gz
rust-d5bd4e233d2bb4415138e384e66379eedbc7e76e.zip
Partially implement `ConstArgHasType`
Diffstat (limited to 'compiler/rustc_trait_selection/src/solve/mod.rs')
-rw-r--r--compiler/rustc_trait_selection/src/solve/mod.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs
index a432090f78c..f9febd290fe 100644
--- a/compiler/rustc_trait_selection/src/solve/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/mod.rs
@@ -197,8 +197,30 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
         goal: Goal<'tcx, (ty::Const<'tcx>, Ty<'tcx>)>,
     ) -> QueryResult<'tcx> {
         let (ct, ty) = goal.predicate;
-        self.eq(goal.param_env, ct.ty(), ty)?;
-        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
+
+        // FIXME(BoxyUwU): Really we should not be calling `ct.ty()` for any variant
+        // other than `ConstKind::Value`. Unfortunately this would require looking in the
+        // env for any `ConstArgHasType` assumptions for parameters and placeholders. I
+        // have not yet gotten around to implementing this though.
+        //
+        // We do still stall on infer vars though as otherwise a goal like:
+        // `ConstArgHasType(?x: usize, usize)` can succeed even though it might later
+        // get unified with some const that is not of type `usize`.
+        match ct.kind() {
+            // FIXME: Ignore effect vars because canonicalization doesn't handle them correctly
+            // and if we stall on the var then we wind up creating ambiguity errors in a probe
+            // for this goal which contains an effect var. Which then ends up ICEing.
+            ty::ConstKind::Infer(ty::InferConst::Var(_)) => {
+                self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
+            }
+            ty::ConstKind::Error(_) => {
+                self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
+            }
+            _ => {
+                self.eq(goal.param_env, ct.ty(), ty)?;
+                self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
+            }
+        }
     }
 }