Skip to content

Commit 2ee8eb2

Browse files
committed
Fix ICE from trying to convert constant error to usize
1 parent ad96323 commit 2ee8eb2

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

compiler/rustc_mir_build/src/build/matches/util.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3535
let tcx = self.tcx;
3636
let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {
3737
match place_resolved.ty(&self.local_decls, tcx).ty.kind() {
38-
ty::Array(_, length) => (length.eval_target_usize(tcx, self.param_env), true),
38+
ty::Array(_, length) => {
39+
let evaluated_const = length.eval(tcx, self.param_env);
40+
let min_length = match evaluated_const.kind() {
41+
ty::ConstKind::Error(_) => return,
42+
ty::ConstKind::Value(value) => value.try_to_target_usize(tcx).unwrap(),
43+
_ => unreachable!(),
44+
};
45+
(min_length, true)
46+
}
3947
_ => ((prefix.len() + suffix.len()).try_into().unwrap(), false),
4048
}
4149
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// edition:2018
2+
// https://github.com/rust-lang/rust/issues/113021
3+
4+
#![feature(generic_const_exprs)]
5+
#![allow(incomplete_features)]
6+
7+
pub async fn a(path: &[(); Abc]) {
8+
//~^ ERROR cannot find value `Abc` in this scope
9+
match path {
10+
[] | _ => (),
11+
}
12+
}
13+
14+
pub async fn b(path: &[(); Abc]) {
15+
//~^ ERROR cannot find value `Abc` in this scope
16+
match path {
17+
&[] | _ => (),
18+
}
19+
}
20+
21+
pub async fn c(path: &[[usize; N_ISLANDS]; PrivateStruct]) -> usize {
22+
//~^ ERROR cannot find value `N_ISLANDS` in this scope
23+
//~| ERROR cannot find value `PrivateStruct` in this scope
24+
match path {
25+
[] | _ => 0,
26+
}
27+
}
28+
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0425]: cannot find value `Abc` in this scope
2+
--> $DIR/match-with-error-length.rs:7:28
3+
|
4+
LL | pub async fn a(path: &[(); Abc]) {
5+
| ^^^ not found in this scope
6+
7+
error[E0425]: cannot find value `Abc` in this scope
8+
--> $DIR/match-with-error-length.rs:14:28
9+
|
10+
LL | pub async fn b(path: &[(); Abc]) {
11+
| ^^^ not found in this scope
12+
13+
error[E0425]: cannot find value `N_ISLANDS` in this scope
14+
--> $DIR/match-with-error-length.rs:21:32
15+
|
16+
LL | pub async fn c(path: &[[usize; N_ISLANDS]; PrivateStruct]) -> usize {
17+
| ^^^^^^^^^ not found in this scope
18+
19+
error[E0425]: cannot find value `PrivateStruct` in this scope
20+
--> $DIR/match-with-error-length.rs:21:44
21+
|
22+
LL | pub async fn c(path: &[[usize; N_ISLANDS]; PrivateStruct]) -> usize {
23+
| ^^^^^^^^^^^^^ not found in this scope
24+
25+
error: aborting due to 4 previous errors
26+
27+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)