]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lang-item:Add LangItem::Kind::RECEIVER
authorlishin <lishin1008@gmail.com>
Mon, 20 Jan 2025 17:53:18 +0000 (17:53 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 21 Jan 2025 13:47:20 +0000 (13:47 +0000)
Add and implement a lang item (receiver) in source code.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc: Add receiver to map.
* util/rust-lang-item.h: Define LangItem::Kind::RECEIVER.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2954.rs: New test.

Signed-off-by: lishin <lishin1008@gmail.com>
gcc/rust/util/rust-lang-item.cc
gcc/rust/util/rust-lang-item.h
gcc/testsuite/rust/compile/issue-2954.rs [new file with mode: 0644]

index 674b18919d27af089db5110d0db5f2edd5810a85..e6bcc85729823a3691d4c1914927b0205cd0c2a3 100644 (file)
@@ -46,6 +46,7 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
   {"shr_assign", Kind::SHR_ASSIGN},
   {"deref", Kind::DEREF},
   {"deref_mut", Kind::DEREF_MUT},
+  {"receiver", Kind::RECEIVER},
   {"index", Kind::INDEX},
   {"index_mut", Kind::INDEX_MUT},
   {"RangeFull", Kind::RANGE_FULL},
index f2e9d7036124775bbe8294d766082fbff3c95d7c..3b3d86eddf2ef0a8c5832628e9a21c4dcd43b669 100644 (file)
@@ -61,6 +61,7 @@ public:
 
     DEREF,
     DEREF_MUT,
+    RECEIVER,
 
     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/index.rs
     INDEX,
diff --git a/gcc/testsuite/rust/compile/issue-2954.rs b/gcc/testsuite/rust/compile/issue-2954.rs
new file mode 100644 (file)
index 0000000..52f7c91
--- /dev/null
@@ -0,0 +1,17 @@
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "receiver"]
+#[unstable(feature = "receiver_trait", issue = "none")]
+// #[doc(hidden)]
+pub trait Receiver {
+    // Empty.
+}
+
+#[unstable(feature = "receiver_trait", issue = "none")]
+impl<T: ?Sized> Receiver for &T {}
+
+#[unstable(feature = "receiver_trait", issue = "none")]
+impl<T: ?Sized> Receiver for &mut T {}
+
+