aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-08-23 19:16:47 +0000
committerGitHub <noreply@github.com>2022-08-23 19:16:47 +0000
commit825a44b40ce6cfa76470e53d0746b1e64b99ee5b (patch)
tree05ac7d0a80bd078e8563ae8649399acec8ccb8fd /gcc/rust/backend
parent241fcaacf600fa4c149d30afa2cf1a42f57c9a0c (diff)
parent36a9255b1b6683bb060021c637997de396445049 (diff)
downloadgcc-825a44b40ce6cfa76470e53d0746b1e64b99ee5b.zip
gcc-825a44b40ce6cfa76470e53d0746b1e64b99ee5b.tar.gz
gcc-825a44b40ce6cfa76470e53d0746b1e64b99ee5b.tar.bz2
Merge #1497
1497: Refactor our casts to follow the Rustc implemention r=philberty a=philberty This gets rid of our old visitor system for cast type checking. Casts depend on type coercions as they are meant to attempt a type coercion before trying a simple cast. This explicitly defines the rules which should be allowed for simple casts. In rustc they use match expressions to write a list of casts which should not be allowed. We have likely missed some rules of what should be allowed but this is at least the start of how to implement this. Fixes #1496 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 412ca09..865ad25 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -237,16 +237,34 @@ CompileExpr::visit (HIR::LazyBooleanExpr &expr)
void
CompileExpr::visit (HIR::TypeCastExpr &expr)
{
- TyTy::BaseType *tyty = nullptr;
+ TyTy::BaseType *type_to_cast_to_ty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
- &tyty))
+ &type_to_cast_to_ty))
{
translated = error_mark_node;
return;
}
- auto type_to_cast_to = TyTyResolveCompile::compile (ctx, tyty);
+ TyTy::BaseType *casted_tyty = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ expr.get_casted_expr ()->get_mappings ().get_hirid (), &casted_tyty))
+ {
+ translated = error_mark_node;
+ return;
+ }
+
+ auto type_to_cast_to = TyTyResolveCompile::compile (ctx, type_to_cast_to_ty);
auto casted_expr = CompileExpr::Compile (expr.get_casted_expr ().get (), ctx);
+
+ std::vector<Resolver::Adjustment> *adjustments = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_cast_autoderef_mappings (
+ expr.get_mappings ().get_hirid (), &adjustments);
+ if (ok)
+ {
+ casted_expr
+ = resolve_adjustements (*adjustments, casted_expr, expr.get_locus ());
+ }
+
translated
= type_cast_expression (type_to_cast_to, casted_expr, expr.get_locus ());
}