Skip to content

Commit 7c85da9

Browse files
Rollup merge of #135380 - compiler-errors:mismatch-valtree, r=lcnr
Make sure we can produce `ConstArgHasWrongType` errors for valtree consts I forgot about `ty::ConstKind::Value` in #134771. The error message here could use some work -- both in the new trait solver and the old trait solver. But unrelated to the issue here. Fixes #135361 -- this was only ICEing in coherence because coherence uses the new trait solver, but I don't think the minimization is worth committing compared to the test I added. r? ```@lcnr``` or ```@BoxyUwU```
2 parents b998c29 + 516a933 commit 7c85da9

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

compiler/rustc_trait_selection/src/solve/fulfill.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ fn fulfillment_error_for_no_solution<'tcx>(
264264
infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args)
265265
}
266266
ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(obligation.param_env),
267-
_ => span_bug!(
267+
ty::ConstKind::Value(ty, _) => ty,
268+
kind => span_bug!(
268269
obligation.cause.span,
269-
"ConstArgHasWrongType failed but we don't know how to compute type"
270+
"ConstArgHasWrongType failed but we don't know how to compute type for {kind:?}"
270271
),
271272
};
272273
FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: the constant `N` is not of type `bool`
2+
--> $DIR/type-mismatch-in-nested-goal.rs:9:50
3+
|
4+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
5+
| ^^^^ expected `bool`, found `usize`
6+
|
7+
note: required by a const generic parameter in `A`
8+
--> $DIR/type-mismatch-in-nested-goal.rs:5:9
9+
|
10+
LL | trait A<const B: bool> {}
11+
| ^^^^^^^^^^^^^ required by this const generic parameter in `A`
12+
13+
error: the constant `true` is not of type `usize`
14+
--> $DIR/type-mismatch-in-nested-goal.rs:13:13
15+
|
16+
LL | needs_a([]);
17+
| ------- ^^ expected `usize`, found `bool`
18+
| |
19+
| required by a bound introduced by this call
20+
|
21+
note: required by a const generic parameter in `needs_a`
22+
--> $DIR/type-mismatch-in-nested-goal.rs:9:12
23+
|
24+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
25+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `needs_a`
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/type-mismatch-in-nested-goal.rs:13:13
29+
|
30+
LL | needs_a([]);
31+
| ------- ^^ expected an array with a size of true, found one with a size of 0
32+
| |
33+
| arguments to this function are incorrect
34+
|
35+
= note: expected array `[u8; true]`
36+
found array `[_; 0]`
37+
note: function defined here
38+
--> $DIR/type-mismatch-in-nested-goal.rs:9:4
39+
|
40+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
41+
| ^^^^^^^ ----------
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: the constant `N` is not of type `bool`
2+
--> $DIR/type-mismatch-in-nested-goal.rs:9:50
3+
|
4+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
5+
| ^^^^ expected `bool`, found `usize`
6+
|
7+
note: required by a const generic parameter in `A`
8+
--> $DIR/type-mismatch-in-nested-goal.rs:5:9
9+
|
10+
LL | trait A<const B: bool> {}
11+
| ^^^^^^^^^^^^^ required by this const generic parameter in `A`
12+
13+
error: the constant `true` is not of type `usize`
14+
--> $DIR/type-mismatch-in-nested-goal.rs:13:13
15+
|
16+
LL | needs_a([]);
17+
| ------- ^^ expected `usize`, found `bool`
18+
| |
19+
| required by a bound introduced by this call
20+
|
21+
note: required by a const generic parameter in `needs_a`
22+
--> $DIR/type-mismatch-in-nested-goal.rs:9:12
23+
|
24+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
25+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `needs_a`
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/type-mismatch-in-nested-goal.rs:13:13
29+
|
30+
LL | needs_a([]);
31+
| ------- ^^ expected an array with a size of true, found one with a size of 0
32+
| |
33+
| arguments to this function are incorrect
34+
|
35+
= note: expected array `[u8; true]`
36+
found array `[_; 0]`
37+
note: function defined here
38+
--> $DIR/type-mismatch-in-nested-goal.rs:9:4
39+
|
40+
LL | fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
41+
| ^^^^^^^ ----------
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
5+
trait A<const B: bool> {}
6+
7+
impl A<true> for () {}
8+
9+
fn needs_a<const N: usize>(_: [u8; N]) where (): A<N> {}
10+
//~^ ERROR the constant `N` is not of type `bool`
11+
12+
pub fn main() {
13+
needs_a([]);
14+
//~^ ERROR the constant `true` is not of type `usize`
15+
//~| ERROR mismatched types
16+
// FIXME(const_generics): we should hide this error as we've already errored above
17+
}

0 commit comments

Comments
 (0)