Skip to content

Commit 7915329

Browse files
committed
Add support for isize and usize type-hints
This bug turned out to be that we expected a usize for the array capacity but the specified capacity turned out to be an integer inference variable which will default to a signed integer. The type resolution was missing handling the type-hints of isize and usize Fixes #1152
1 parent 243ef0d commit 7915329

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
133133
ok = context->lookup_builtin ("f64", &infered);
134134
break;
135135

136+
case CORETYPE_ISIZE:
137+
ok = context->lookup_builtin ("isize", &infered);
138+
break;
139+
140+
case CORETYPE_USIZE:
141+
ok = context->lookup_builtin ("usize", &infered);
142+
break;
143+
136144
default:
137145
ok = true;
138146
infered

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ class TypeCheckExpr : public TypeCheckBase
619619
= (negated_expr_ty->get_kind () == TyTy::TypeKind::INT)
620620
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::UINT)
621621
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::FLOAT)
622+
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::ISIZE)
623+
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::USIZE)
622624
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::INFER
623625
&& (((TyTy::InferType *) negated_expr_ty)->get_infer_kind ()
624626
== TyTy::InferType::INTEGRAL))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn test() {
2+
let f = [0; -4_isize];
3+
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
4+
// { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
5+
let f = [0_usize; -1_isize];
6+
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
7+
// { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
8+
}

0 commit comments

Comments
 (0)