diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-01-31 14:39:29 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2023-02-05 00:10:48 +0000 |
commit | d4e6b64e7f9e23aeb5d3c40665f18091575921ed (patch) | |
tree | 980f386af89a8d7a2357588e08a061dd5d1be841 /gcc | |
parent | e612713029296dac8429e4b00ec7659bcad5cffe (diff) | |
download | gcc-d4e6b64e7f9e23aeb5d3c40665f18091575921ed.zip gcc-d4e6b64e7f9e23aeb5d3c40665f18091575921ed.tar.gz gcc-d4e6b64e7f9e23aeb5d3c40665f18091575921ed.tar.bz2 |
gccrs: Add missing Sized, Copy and Clone lang item mappings
We need these lang items to be defined and later down the line the mappings
will be used to implement proper copy and clone logic.
Fixes #1786
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* util/rust-lang-item.h:
gcc/testsuite/ChangeLog:
* rust/compile/issue-1786.rs: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/util/rust-lang-item.h | 24 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-1786.rs | 23 |
2 files changed, 47 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 52f53fa..5bad08a 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -80,6 +80,12 @@ public: FN_ONCE, FN_ONCE_OUTPUT, + // markers + COPY, + CLONE, + SIZED, + + // delimiter UNKNOWN, }; @@ -237,6 +243,18 @@ public: { return ItemType::FN_ONCE_OUTPUT; } + else if (item.compare ("copy") == 0) + { + return ItemType::COPY; + } + else if (item.compare ("clone") == 0) + { + return ItemType::CLONE; + } + else if (item.compare ("sized") == 0) + { + return ItemType::SIZED; + } return ItemType::UNKNOWN; } @@ -321,6 +339,12 @@ public: return "fn_once"; case FN_ONCE_OUTPUT: return "fn_once_output"; + case COPY: + return "copy"; + case CLONE: + return "clone"; + case SIZED: + return "sized"; case UNKNOWN: return "<UNKNOWN>"; diff --git a/gcc/testsuite/rust/compile/issue-1786.rs b/gcc/testsuite/rust/compile/issue-1786.rs new file mode 100644 index 0000000..f73b63d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1786.rs @@ -0,0 +1,23 @@ +#[lang = "clone"] +trait Clone { + fn clone(&self) -> Self; + + fn clone_from(&mut self, source: &Self) { + *self = source.clone() + } +} + +#[lang = "copy"] +pub trait Copy: Clone { + // Empty. +} + +mod impls { + use super::Clone; + + impl Clone for char { + fn clone(&self) -> Self { + *self + } + } +} |