Normalize before computing ConstArgHasType goal

This commit is contained in:
Michael Goulet
2025-06-20 19:43:17 +00:00
parent 2801f9aaf9
commit 87c8aa1ff6
4 changed files with 29 additions and 6 deletions

View File

@@ -191,6 +191,7 @@ where
goal: Goal<I, (I::Const, I::Ty)>, goal: Goal<I, (I::Const, I::Ty)>,
) -> QueryResult<I> { ) -> QueryResult<I> {
let (ct, ty) = goal.predicate; let (ct, ty) = goal.predicate;
let ct = self.structurally_normalize_const(goal.param_env, ct)?;
let ct_ty = match ct.kind() { let ct_ty = match ct.kind() {
ty::ConstKind::Infer(_) => { ty::ConstKind::Infer(_) => {

View File

@@ -1,6 +0,0 @@
//@ known-bug: #139905
trait a<const b: bool> {}
impl a<{}> for () {}
trait c {}
impl<const d: u8> c for () where (): a<d> {}
impl c for () {}

View File

@@ -0,0 +1,19 @@
trait A<const B: bool> {}
// vv- Let's call this const "UNEVALUATED" for the comment below.
impl A<{}> for () {}
//~^ ERROR mismatched types
// During overlap check, we end up trying to prove `(): A<?0c>`. Inference guides
// `?0c = UNEVALUATED` (which is the `{}` const in the erroneous impl). We then
// fail to prove `ConstArgHasType<UNEVALUATED, u8>` since `UNEVALUATED` has the
// type `bool` from the type_of query. We then deeply normalize the predicate for
// error reporting, which ends up normalizing `UNEVALUATED` to a ConstKind::Error.
// This ended up ICEing when trying to report an error for the `ConstArgHasType`
// predicate, since we don't expect `ConstArgHasType(ERROR, Ty)` to ever fail.
trait C<const D: u8> {}
impl<const D: u8> C<D> for () where (): A<D> {}
impl<const D: u8> C<D> for () {}
fn main() {}

View File

@@ -0,0 +1,9 @@
error[E0308]: mismatched types
--> $DIR/normalize-before-const-arg-has-type-goal.rs:4:8
|
LL | impl A<{}> for () {}
| ^^ expected `bool`, found `()`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.