diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-24 18:45:34 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-26 09:14:10 +0000 |
commit | c7af812802ff64a88b4d251dae83377f45c0a8a3 (patch) | |
tree | 8996e916a4375af6f33d1a835218a0e1fb003fd6 /gcc/rust/backend/rust-compile-expr.h | |
parent | 3b8cbff816c969aa43aca9c611b3c3f9ef5a1af5 (diff) | |
download | gcc-c7af812802ff64a88b4d251dae83377f45c0a8a3.zip gcc-c7af812802ff64a88b4d251dae83377f45c0a8a3.tar.gz gcc-c7af812802ff64a88b4d251dae83377f45c0a8a3.tar.bz2 |
Support dereference operator overloading
This adds in support for deref lang-item operator overloads. Deref operator
overloading is an interesting case of the libcore interaction with the
compiler. The deref operator lang item is:
```rust
pub trait Deref {
type Target;
fn deref(&self) -> &Self::Target;
}
```
It has two default impl's one for '&T' and '&mut T' to apply genericly.
The reason it is interesting is from the prototype the deref lang item
always returns &Self::Target in all cases regardless of mutability, the
lang item here is designed to wrap up any dereference such that when
applied it guarentees the type system you will get back an immutable
reference to something. The reason for doing this is more clear when
thinking about autoderef and method-resolution and how you apply
dereference operations to custom types and a test case is included for
that.
The autoderef mechanism will now need to be updated to support drefs fully.
Fixes #809
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 46d501a..1e8e1f6 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -979,26 +979,7 @@ public: = ctx->get_backend ()->address_expression (main_expr, expr.get_locus ()); } - void visit (HIR::DereferenceExpr &expr) override - { - tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); - - TyTy::BaseType *tyty = nullptr; - if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), - &tyty)) - { - rust_fatal_error (expr.get_locus (), - "did not resolve type for this TupleExpr"); - return; - } - - tree expected_type = TyTyResolveCompile::compile (ctx, tyty); - bool known_valid = true; - translated - = ctx->get_backend ()->indirect_expression (expected_type, main_expr, - known_valid, - expr.get_locus ()); - } + void visit (HIR::DereferenceExpr &expr) override; protected: tree compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, |