Skip to content

Commit ec2f40c

Browse files
committed
Auto merge of rust-lang#109740 - compiler-errors:new-solver-deep-reject-placeholder-consts, r=lcnr
Don't ICE on placeholder consts in deep reject Since we canonicalize const params into placeholder consts, we need to be able to handle them during deep reject. r? `@lcnr` (though maybe `@oli-obk` can look at this one too, if he wants 😸) Fixes compiler-errors/next-solver-hir-issues#10
2 parents 789ee5e + 1ce6e2b commit ec2f40c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Diff for: compiler/rustc_middle/src/ty/fast_reject.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ impl DeepRejectCtxt {
312312
// Impls cannot contain these types as these cannot be named directly.
313313
ty::FnDef(..) | ty::Closure(..) | ty::Generator(..) => false,
314314

315+
// Placeholder types don't unify with anything on their own
315316
ty::Placeholder(..) | ty::Bound(..) => false,
316317

317318
// Depending on the value of `treat_obligation_params`, we either
@@ -359,6 +360,9 @@ impl DeepRejectCtxt {
359360
TreatParams::AsCandidateKey => true,
360361
},
361362

363+
// Placeholder consts don't unify with anything on their own
364+
ty::ConstKind::Placeholder(_) => false,
365+
362366
// As we don't necessarily eagerly evaluate constants,
363367
// they might unify with any value.
364368
ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => {
@@ -371,7 +375,7 @@ impl DeepRejectCtxt {
371375

372376
ty::ConstKind::Infer(_) => true,
373377

374-
ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
378+
ty::ConstKind::Bound(..) => {
375379
bug!("unexpected obl const: {:?}", obligation_ct)
376380
}
377381
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `[T; N]: Foo` is not satisfied
2+
--> $DIR/const-param-placeholder.rs:17:17
3+
|
4+
LL | needs_foo::<[T; N]>();
5+
| ^^^^^^ the trait `Foo` is not implemented for `[T; N]`
6+
|
7+
= help: the trait `Foo` is implemented for `[T; 1]`
8+
note: required by a bound in `needs_foo`
9+
--> $DIR/const-param-placeholder.rs:8:17
10+
|
11+
LL | fn needs_foo<F: Foo>() {}
12+
| ^^^ required by this bound in `needs_foo`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// revisions: pass fail
3+
//[pass] check-pass
4+
5+
struct Wrapper<T, const N: usize>([T; N]);
6+
7+
trait Foo {}
8+
fn needs_foo<F: Foo>() {}
9+
10+
#[cfg(fail)]
11+
impl<T> Foo for [T; 1] {}
12+
13+
#[cfg(pass)]
14+
impl<T, const N: usize> Foo for [T; N] {}
15+
16+
fn test<T, const N: usize>() {
17+
needs_foo::<[T; N]>();
18+
//[fail]~^ ERROR the trait bound `[T; N]: Foo` is not satisfied
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)