aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-07-30 00:19:15 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-07-30 00:08:48 +0000
commit5ad0febb770177b5d32aa4f11a7b377de2773d84 (patch)
tree4f56ab08f1dc5f4bf8f39323627cae2f1178b3d2 /gcc/rust
parent5785d329b1f4782ea4abf75fc4fd22fe4dfed5d8 (diff)
downloadgcc-5ad0febb770177b5d32aa4f11a7b377de2773d84.zip
gcc-5ad0febb770177b5d32aa4f11a7b377de2773d84.tar.gz
gcc-5ad0febb770177b5d32aa4f11a7b377de2773d84.tar.bz2
gccrs: fix ice when function is outside of context
Fixes #2477 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): We need to check if a function context exists gcc/testsuite/ChangeLog: * rust/compile/issue-2477.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 06d4c4c..ddf890c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -150,6 +150,14 @@ TypeCheckExpr::visit (HIR::TupleExpr &expr)
void
TypeCheckExpr::visit (HIR::ReturnExpr &expr)
{
+ if (!context->have_function_context ())
+ {
+ rust_error_at (expr.get_locus (),
+ "return statement outside of function body");
+ infered = new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
+ return;
+ }
+
auto fn_return_tyty = context->peek_return_type ();
location_t expr_locus = expr.has_return_expr ()
? expr.get_expr ()->get_locus ()