From: Owen Avery Date: Tue, 10 Jan 2023 00:54:55 +0000 (-0500) Subject: gccrs: Reuse TypeCheckPattern on LetStmt's X-Git-Tag: basepoints/gcc-14~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=364f4cd3072cb1fa99431fe001f03451059f075e;p=thirdparty%2Fgcc.git gccrs: Reuse TypeCheckPattern on LetStmt's Update Rust type-checking to reuse TypeCheckPattern on HIR::LetStmt's. This will unify the paths and improve error handling. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Cleanup LetStmt type checking. Signed-off-by: Owen Avery --- diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc index 437782e81020..956249a76070 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc @@ -82,7 +82,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) { infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ()); - const HIR::Pattern &stmt_pattern = *stmt.get_pattern (); + HIR::Pattern &stmt_pattern = *stmt.get_pattern (); TyTy::BaseType *init_expr_ty = nullptr; Location init_expr_locus; if (stmt.has_init_expr ()) @@ -111,27 +111,25 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) TyTy::TyWithLocation (specified_ty, specified_ty_locus), TyTy::TyWithLocation (init_expr_ty, init_expr_locus), stmt.get_locus ()); - context->insert_type (stmt_pattern.get_pattern_mappings (), specified_ty); + TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); } else { // let x:i32; if (specified_ty != nullptr) { - context->insert_type (stmt_pattern.get_pattern_mappings (), - specified_ty); + TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); } // let x = 123; else if (init_expr_ty != nullptr) { - context->insert_type (stmt_pattern.get_pattern_mappings (), - init_expr_ty); + TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty); } // let x; else { - context->insert_type ( - stmt_pattern.get_pattern_mappings (), + TypeCheckPattern::Resolve ( + &stmt_pattern, new TyTy::InferType ( stmt_pattern.get_pattern_mappings ().get_hirid (), TyTy::InferType::InferTypeKind::GENERAL, stmt.get_locus ()));