aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-06-05 16:37:29 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-06-05 16:40:19 +0100
commit1c0f8d6d2a22ce498ef3f1bfd60a3867a90c8130 (patch)
tree4ac87f4d6dc73a876525a3dc3c280283f9baa1ea /gcc/rust/backend
parent69b3e488803f684d9d956223a7f410d219cced24 (diff)
downloadgcc-1c0f8d6d2a22ce498ef3f1bfd60a3867a90c8130.zip
gcc-1c0f8d6d2a22ce498ef3f1bfd60a3867a90c8130.tar.gz
gcc-1c0f8d6d2a22ce498ef3f1bfd60a3867a90c8130.tar.bz2
This is the initial building blocks for Traits
We can compile TraitImpls, since before we can actually start checking trait obligations we need to be able to implement the trait first. More desugaring is needed in HIR to make TraitImpls contain normal impl items to avoid seperation in how impl blocks are handled. Fixes #395 #472
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h8
-rw-r--r--gcc/rust/backend/rust-compile-item.h16
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index a5ca13b..a4fb6d1 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -42,6 +42,14 @@ public:
item->accept_vis (compiler);
}
+ static void Compile (TyTy::BaseType *self, HIR::TraitImplItem *item,
+ Context *ctx, bool compile_fns,
+ TyTy::BaseType *concrete = nullptr)
+ {
+ CompileInherentImplItem compiler (self, ctx, compile_fns, concrete);
+ item->accept_vis (compiler);
+ }
+
void visit (HIR::ConstantItem &constant) override
{
TyTy::BaseType *resolved_type = nullptr;
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index e3b6d0f..e681652 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -290,6 +290,22 @@ public:
compile_fns);
}
+ void visit (HIR::TraitImpl &impl_block) override
+ {
+ TyTy::BaseType *self_lookup = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ impl_block.get_type ()->get_mappings ().get_hirid (), &self_lookup))
+ {
+ rust_error_at (impl_block.get_locus (),
+ "failed to resolve type of impl");
+ return;
+ }
+
+ for (auto &impl_item : impl_block.get_impl_items ())
+ CompileInherentImplItem::Compile (self_lookup, impl_item.get (), ctx,
+ compile_fns);
+ }
+
private:
CompileItem (Context *ctx, bool compile_fns, TyTy::BaseType *concrete)
: HIRCompileBase (ctx), compile_fns (compile_fns), concrete (concrete)