From d5bd4e233d2bb4415138e384e66379eedbc7e76e Mon Sep 17 00:00:00 2001 From: Boxy Date: Wed, 29 May 2024 17:06:50 +0100 Subject: Partially implement `ConstArgHasType` --- compiler/rustc_trait_selection/src/solve/mod.rs | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_trait_selection/src/solve') 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) + } + } } } -- cgit 1.4.1-3-g733a5