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/util/rust-hir-map.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/util/rust-hir-map.h')
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 4f8c389..77a4caf 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -51,6 +51,8 @@ public: DIV_ASSIGN, REM_ASSIGN, + DEREF, + UNKNOWN, }; @@ -104,6 +106,10 @@ public: { return ItemType::REM_ASSIGN; } + else if (item.compare ("deref") == 0) + { + return ItemType::DEREF; + } return ItemType::UNKNOWN; } @@ -136,6 +142,8 @@ public: return "div_assign"; case REM_ASSIGN: return "rem_assign"; + case DEREF: + return "deref"; case UNKNOWN: break; |