Skip to content

Normalize before computing ConstArgHasType goal in new solver #142806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you want boxy to review this, but it feels very much correct to require normalizing before matching on the const kind here :> it's what we do for all other matches on kind as well.

so r=me here


let ct_ty = match ct.kind() {
ty::ConstKind::Infer(_) => {
Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/139905.rs

This file was deleted.

19 changes: 19 additions & 0 deletions tests/ui/consts/normalize-before-const-arg-has-type-goal.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.
Loading