Skip to content

Commit 87c8aa1

Browse files
Normalize before computing ConstArgHasType goal
1 parent 2801f9a commit 87c8aa1

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ where
191191
goal: Goal<I, (I::Const, I::Ty)>,
192192
) -> QueryResult<I> {
193193
let (ct, ty) = goal.predicate;
194+
let ct = self.structurally_normalize_const(goal.param_env, ct)?;
194195

195196
let ct_ty = match ct.kind() {
196197
ty::ConstKind::Infer(_) => {

tests/crashes/139905.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait A<const B: bool> {}
2+
3+
// vv- Let's call this const "UNEVALUATED" for the comment below.
4+
impl A<{}> for () {}
5+
//~^ ERROR mismatched types
6+
7+
// During overlap check, we end up trying to prove `(): A<?0c>`. Inference guides
8+
// `?0c = UNEVALUATED` (which is the `{}` const in the erroneous impl). We then
9+
// fail to prove `ConstArgHasType<UNEVALUATED, u8>` since `UNEVALUATED` has the
10+
// type `bool` from the type_of query. We then deeply normalize the predicate for
11+
// error reporting, which ends up normalizing `UNEVALUATED` to a ConstKind::Error.
12+
// This ended up ICEing when trying to report an error for the `ConstArgHasType`
13+
// predicate, since we don't expect `ConstArgHasType(ERROR, Ty)` to ever fail.
14+
15+
trait C<const D: u8> {}
16+
impl<const D: u8> C<D> for () where (): A<D> {}
17+
impl<const D: u8> C<D> for () {}
18+
19+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/normalize-before-const-arg-has-type-goal.rs:4:8
3+
|
4+
LL | impl A<{}> for () {}
5+
| ^^ expected `bool`, found `()`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)