From 4854e2979f1bd057a0bff19025f10069babf7e62 Mon Sep 17 00:00:00 2001 From: lishin Date: Mon, 20 Jan 2025 17:53:18 +0000 Subject: [PATCH] lang-item:Add LangItem::Kind::RECEIVER 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 --- gcc/rust/util/rust-lang-item.cc | 1 + gcc/rust/util/rust-lang-item.h | 1 + gcc/testsuite/rust/compile/issue-2954.rs | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2954.rs diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc index 674b18919d2..e6bcc857298 100644 --- a/gcc/rust/util/rust-lang-item.cc +++ b/gcc/rust/util/rust-lang-item.cc @@ -46,6 +46,7 @@ const BiMap 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}, diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index f2e9d703612..3b3d86eddf2 100644 --- a/gcc/rust/util/rust-lang-item.h +++ b/gcc/rust/util/rust-lang-item.h @@ -61,6 +61,7 @@ class LangItem 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 index 00000000000..52f7c9140ec --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2954.rs @@ -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 Receiver for &T {} + +#[unstable(feature = "receiver_trait", issue = "none")] +impl Receiver for &mut T {} + +