Skip to content

Commit e43e5d0

Browse files
committed
Added handling of ConstKind::Expr when checking for is_const_evaluatable and having non region param
1 parent 8de6f99 commit e43e5d0

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ pub fn is_const_evaluatable<'tcx>(
5656
if ct.has_non_region_infer() {
5757
return Err(NotConstEvaluatable::MentionsInfer);
5858
} else if ct.has_non_region_param() {
59-
return Err(NotConstEvaluatable::MentionsParam);
59+
match unexpanded_ct.kind() {
60+
ty::ConstKind::Expr(_) => {
61+
return Err(NotConstEvaluatable::Error(tcx.sess.delay_span_bug(
62+
span,
63+
"evaluating `ConstKind::Expr` when having non region param is not supported",
64+
)))
65+
}
66+
_ => return Err(NotConstEvaluatable::MentionsParam),
67+
};
6068
}
6169
}
6270

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
fn foo<const N: usize>(
5+
_: [u8; {
6+
{
7+
N
8+
}
9+
}],
10+
) {
11+
}
12+
13+
fn ice<const L: usize>()
14+
where
15+
[(); (L - 1) + 1 + L]:,
16+
{
17+
foo::<_, L>([(); L + 1 + L]);
18+
//~^ ERROR: mismatched types
19+
//~^^ ERROR: unconstrained generic constant
20+
//~^^^ ERROR: function takes 1 generic argument but 2 generic arguments were supplied
21+
//~^^^^ ERROR: unconstrained generic constant
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error[E0107]: function takes 1 generic argument but 2 generic arguments were supplied
2+
--> $DIR/issue_114151.rs:17:5
3+
|
4+
LL | foo::<_, L>([(); L + 1 + L]);
5+
| ^^^ - help: remove this generic argument
6+
| |
7+
| expected 1 generic argument
8+
|
9+
note: function defined here, with 1 generic parameter: `N`
10+
--> $DIR/issue_114151.rs:4:4
11+
|
12+
LL | fn foo<const N: usize>(
13+
| ^^^ --------------
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/issue_114151.rs:17:18
17+
|
18+
LL | foo::<_, L>([(); L + 1 + L]);
19+
| ^^ expected `u8`, found `()`
20+
21+
error: unconstrained generic constant
22+
--> $DIR/issue_114151.rs:17:22
23+
|
24+
LL | foo::<_, L>([(); L + 1 + L]);
25+
| ^^^^^^^^^
26+
|
27+
= help: try adding a `where` bound using this expression: `where [(); L + 1 + L]:`
28+
29+
error: unconstrained generic constant
30+
--> $DIR/issue_114151.rs:17:17
31+
|
32+
LL | foo::<_, L>([(); L + 1 + L]);
33+
| ----------- ^^^^^^^^^^^^^^^
34+
| |
35+
| required by a bound introduced by this call
36+
|
37+
= help: try adding a `where` bound using this expression: `where [(); {
38+
{
39+
N
40+
}
41+
}]:`
42+
note: required by a bound in `foo`
43+
--> $DIR/issue_114151.rs:5:13
44+
|
45+
LL | fn foo<const N: usize>(
46+
| --- required by a bound in this function
47+
LL | _: [u8; {
48+
| _____________^
49+
LL | | {
50+
LL | | N
51+
LL | | }
52+
LL | | }],
53+
| |_____^ required by this bound in `foo`
54+
55+
error: aborting due to 4 previous errors
56+
57+
Some errors have detailed explanations: E0107, E0308.
58+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)