Normalize before computing ConstArgHasType goal
This commit is contained in:
@@ -191,6 +191,7 @@ where
|
||||
goal: Goal<I, (I::Const, I::Ty)>,
|
||||
) -> QueryResult<I> {
|
||||
let (ct, ty) = goal.predicate;
|
||||
let ct = self.structurally_normalize_const(goal.param_env, ct)?;
|
||||
|
||||
let ct_ty = match ct.kind() {
|
||||
ty::ConstKind::Infer(_) => {
|
||||
|
||||
@@ -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 () {}
|
||||
19
tests/ui/consts/normalize-before-const-arg-has-type-goal.rs
Normal file
19
tests/ui/consts/normalize-before-const-arg-has-type-goal.rs
Normal 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() {}
|
||||
@@ -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`.
|
||||
Reference in New Issue
Block a user