]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: lang-item:Add LangItem::Kind::RECEIVER
authorlishin <lishin1008@gmail.com>
Mon, 20 Jan 2025 17:53:18 +0000 (17:53 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:06:51 +0000 (13:06 +0100)
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 e038e900f947b8afe67158888622e62f7d970a29..7460df0a6daaad0702a643123d59299d0f03d885 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 f947f3f021c0023cb451a74b624604e361da5a30..e68f055908453b2e8b27fa08495fe59fd1a90712 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 {}
+
+