Make sure we can produce ConstArgHasWrongType errors for valtree consts · rust-lang/rust@516a933 (original) (raw)
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -264,9 +264,10 @@ fn fulfillment_error_for_no_solution<'tcx>( | ||
264 | 264 | infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args) |
265 | 265 | } |
266 | 266 | 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!( | |
268 | 269 | 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:?}" | |
270 | 271 | ), |
271 | 272 | }; |
272 | 273 | FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType { |
Original file line number | Diff line number | Diff 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(_: [u8; N]) where (): A {} | |
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 {} | |
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(_: [u8; N]) where (): A {} | |
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(_: [u8; N]) where (): A {} | |
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 number | Diff line number | Diff 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(_: [u8; N]) where (): A {} | |
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 {} | |
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(_: [u8; N]) where (): A {} | |
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(_: [u8; N]) where (): A {} | |
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 number | Diff line number | Diff 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 | +} |