Skip to content

Commit 7e44c93

Browse files
committed
gccrs: Fix ICE on copied array expressions
We need to check for errors on the number of copies expression before trying to const fold it otherwise it will just fail in the const evaluator. Fixes #4165 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): check for error gcc/testsuite/ChangeLog: * rust/compile/issue-4165.rs: New test. Signed-off-by: Philip Herron <[email protected]>
1 parent 4b3858e commit 7e44c93

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

gcc/rust/typecheck/rust-hir-type-check-expr.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,13 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
10961096
context->insert_type (elems.get_num_copies_expr ().get_mappings (),
10971097
expected_ty);
10981098

1099-
unify_site (
1099+
auto result = unify_site (
11001100
expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty),
11011101
TyTy::TyWithLocation (capacity_expr_ty,
11021102
elems.get_num_copies_expr ().get_locus ()),
11031103
expr.get_locus ());
1104+
if (result->is<TyTy::ErrorType> ())
1105+
return;
11041106

11051107
capacity_expr = &elems.get_num_copies_expr ();
11061108
capacity_type = expected_ty;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const N: usize = 2;
2+
const ARR: [i32; N] = [42; X];
3+
// { dg-error {cannot find value .X. in this scope \[E0425\]} "" { target *-*-* } .-1 }
4+
// { dg-error {mismatched types, expected .\[i32; 2]. but got .<tyty::error>. \[E0308\]} "" { target *-*-* } .-2 }
5+
// { dg-error {mismatched types, expected .usize. but got .bool. \[E0308\]} "" { target *-*-* } .-3 }
6+
const X: bool = (N[0] == 99) && (ARR[0] == 0);
7+
// { dg-error {the type .usize. cannot be indexed by .<integer>. \[E0277\]} "" { target *-*-* } .-1 }
8+
// { dg-error {mismatched types, expected .<tyty::error>. but got .<integer>. \[E0308\]} "" { target *-*-* } .-2 }
9+
10+
fn main() {
11+
let _ = X;
12+
}

0 commit comments

Comments
 (0)