Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccrs: match arms are a LUB #3360

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,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);

Expand Down
7 changes: 4 additions & 3 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1532,9 +1532,10 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
for (size_t i = 1; i < kase_block_tys.size (); i++)
{
TyTy::BaseType *kase_ty = kase_block_tys.at (i);
infered = unify_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (infered),
TyTy::TyWithLocation (kase_ty), expr.get_locus ());
infered
= coercion_site (expr.get_mappings ().get_hirid (),
TyTy::TyWithLocation (infered),
TyTy::TyWithLocation (kase_ty), expr.get_locus ());
}
}

Expand Down
10 changes: 0 additions & 10 deletions gcc/rust/typecheck/rust-unify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// <http://www.gnu.org/licenses/>.

#include "rust-unify.h"
#include "rust-tyty.h"

namespace Rust {
namespace Resolver {
Expand Down Expand Up @@ -238,15 +237,6 @@ UnifyRules::go ()
}
}

// The never type should always get coerced to the type it's being matched
// against, so in that case, ltype. This avoids doing the same check in all
// the `expect_*` functions.
// However, this does not work if we have an annoying ltype - like INFER.
// TODO: Is ltype == Infer the only special case here? What about projections?
// references?
if (rtype->get_kind () == TyTy::NEVER && ltype->get_kind () != TyTy::INFER)
return ltype->clone ();

switch (ltype->get_kind ())
{
case TyTy::INFER:
Expand Down
Loading