diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-22 11:45:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 11:45:59 +0000 |
commit | b392376cc521230c8b254841ab036541317dc907 (patch) | |
tree | eca4ecc8e78270566cf628ff18b8996d4c381c1e /gcc | |
parent | d541ded4855d0b4273a986b15ff497c45dbc6c78 (diff) | |
parent | 7915329a0c552245488710d7561a6a76f784c0a7 (diff) | |
download | gcc-b392376cc521230c8b254841ab036541317dc907.zip gcc-b392376cc521230c8b254841ab036541317dc907.tar.gz gcc-b392376cc521230c8b254841ab036541317dc907.tar.bz2 |
Merge #1154
1154: Add support for isize and usize type-hints r=philberty a=philberty
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
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-base.cc | 8 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-1152.rs | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index a924866..4e8fa26 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -133,6 +133,14 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings, ok = context->lookup_builtin ("f64", &infered); break; + case CORETYPE_ISIZE: + ok = context->lookup_builtin ("isize", &infered); + break; + + case CORETYPE_USIZE: + ok = context->lookup_builtin ("usize", &infered); + break; + default: ok = true; infered diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 5db00a4..630eb60 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -619,6 +619,8 @@ public: = (negated_expr_ty->get_kind () == TyTy::TypeKind::INT) || (negated_expr_ty->get_kind () == TyTy::TypeKind::UINT) || (negated_expr_ty->get_kind () == TyTy::TypeKind::FLOAT) + || (negated_expr_ty->get_kind () == TyTy::TypeKind::ISIZE) + || (negated_expr_ty->get_kind () == TyTy::TypeKind::USIZE) || (negated_expr_ty->get_kind () == TyTy::TypeKind::INFER && (((TyTy::InferType *) negated_expr_ty)->get_infer_kind () == TyTy::InferType::INTEGRAL)) diff --git a/gcc/testsuite/rust/compile/issue-1152.rs b/gcc/testsuite/rust/compile/issue-1152.rs new file mode 100644 index 0000000..18eee9e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1152.rs @@ -0,0 +1,8 @@ +fn test() { + let f = [0; -4_isize]; + // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 } + // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 } + let f = [0_usize; -1_isize]; + // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 } + // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 } +} |