diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-01-09 16:47:47 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-01-10 09:28:52 +0000 |
commit | b4a525ce39716cd1e9355b8503c78f3dd0fdbbb3 (patch) | |
tree | 0a237601854ec98ce80de894f2a121b75c2ecb5c /gcc/rust/backend/rust-compile-expr.cc | |
parent | c960e034f3d66f88127818cabfd486e68d717872 (diff) | |
download | gcc-b4a525ce39716cd1e9355b8503c78f3dd0fdbbb3.zip gcc-b4a525ce39716cd1e9355b8503c78f3dd0fdbbb3.tar.gz gcc-b4a525ce39716cd1e9355b8503c78f3dd0fdbbb3.tar.bz2 |
gccrs: match arms are a LUB
Unify rules are not the same as coercion rules. The coercion of ! is
allowed to any type but not for a unify site which is different.
Match arms are another least upper bound coercion.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): implement coercion
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): this is an LUB
* typecheck/rust-unify.cc (UnifyRules::go): remove unify ! coercion
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 6a0db31..c24a22a 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1156,8 +1156,19 @@ CompileExpr::visit (HIR::MatchExpr &expr) location_t arm_locus = kase_arm.get_locus (); tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx); tree result_reference = Backend::var_expression (tmp, arm_locus); + + TyTy::BaseType *actual = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type ( + kase.get_expr ().get_mappings ().get_hirid (), &actual); + rust_assert (ok); + + tree coerced_result + = coercion_site (kase.get_expr ().get_mappings ().get_hirid (), + kase_expr_tree, actual, expr_tyty, + expr.get_locus (), arm_locus); + tree assignment - = Backend::assignment_statement (result_reference, kase_expr_tree, + = Backend::assignment_statement (result_reference, coerced_result, arm_locus); ctx->add_statement (assignment); |