aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-09-17 16:41:25 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-09-17 16:41:25 +0100
commitd9a0a5f864b69c68d410a14e0aa7ccbaae7eb144 (patch)
tree590ca34cd83110c08f0d04c29ba41b3d0561e092 /gcc/rust
parentd144eea86290e8efc700d8042e9b517158b9f916 (diff)
downloadgcc-d9a0a5f864b69c68d410a14e0aa7ccbaae7eb144.zip
gcc-d9a0a5f864b69c68d410a14e0aa7ccbaae7eb144.tar.gz
gcc-d9a0a5f864b69c68d410a14e0aa7ccbaae7eb144.tar.bz2
Allow for coercion of structures over to dynamic objects in type system
This is the initial support for allowing a coercion of something like: ```rust let a = Foo(123); let b:&dyn Bound = &a; ``` The coercion will need to ensure that 'a' meets the specified bounds of the dynamic object. Addresses #197
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-tyty-coercion.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h
index d46f1d4..976997d 100644
--- a/gcc/rust/typecheck/rust-tyty-coercion.h
+++ b/gcc/rust/typecheck/rust-tyty-coercion.h
@@ -24,6 +24,7 @@
#include "rust-tyty-visitor.h"
#include "rust-hir-map.h"
#include "rust-hir-type-check.h"
+#include "rust-hir-type-bounds.h"
extern ::Backend *
rust_get_backend ();
@@ -1390,6 +1391,16 @@ public:
resolved = base->clone ();
}
+ void visit (ADTType &type) override
+ {
+ Location ref_locus = mappings->lookup_location (type.get_ref ());
+ bool ok = base->bounds_compatible (type, ref_locus, true);
+ if (!ok)
+ return;
+
+ resolved = base->clone ();
+ }
+
private:
BaseType *get_base () override { return base; }