From: Enes Cevik <[email protected]>
This patch adds pin/unpin lang items to the compiler but not fully tested
due to issues Rust-GCC/gccrs#4709 and Rust-GCC/gccrs#4678 so we tested
auto trait and negative impls behaviors.
gcc/rust/ChangeLog:
* util/rust-lang-item.cc (Rust::LangItem::lang_items): Add pin
and unpin lang items to the BiMap.
* util/rust-lang-item.h (class LangItem): Add PIN and UNPIN to
the Kind enum.
gcc/testsuite/ChangeLog:
* rust/compile/lang-pin-unpin.rs: New test.
Signed-off-by: Enes Cevik <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/fa1a84b6b8225b6ca8c59c80ef4d9a7eb52017a1
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4678: https://github.com/Rust-GCC/gccrs/issues/4678
- Rust-GCC/gccrs#4709: https://github.com/Rust-GCC/gccrs/issues/4709
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4720
gcc/rust/util/rust-lang-item.cc | 2 ++
gcc/rust/util/rust-lang-item.h | 2 ++
gcc/testsuite/rust/compile/lang-pin-unpin.rs | 38 ++++++++++++++++++++
3 files changed, 42 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/lang-pin-unpin.rs
diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index b00ce9903..5a3e939f9 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -144,6 +144,8 @@ const BiMap<std::string, LangItem::Kind>
Rust::LangItem::lang_items = {{
{"generator_state", Kind::GENERATOR_STATE},
{"va_list", Kind::VA_LIST},
+ {"pin", Kind::PIN},
+ {"unpin", Kind::UNPIN},
}};
tl::optional<LangItem::Kind>
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 133313826..766b47c79 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -180,6 +180,8 @@ public:
GENERATOR_STATE,
VA_LIST,
+ PIN,
+ UNPIN,
};
static const BiMap<std::string, Kind> lang_items;
diff --git a/gcc/testsuite/rust/compile/lang-pin-unpin.rs
b/gcc/testsuite/rust/compile/lang-pin-unpin.rs
new file mode 100644
index 000000000..dac96fe6c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/lang-pin-unpin.rs
@@ -0,0 +1,38 @@
+#![feature(no_core, lang_items, optin_builtin_traits, negative_impls)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "unpin"]
+pub auto trait Unpin {}
+
+#[lang = "pin"]
+pub struct Pin<P> {
+ pointer: P,
+}
+
+impl<P> Pin<P> {
+ pub fn new(pointer: P) -> Pin<P>
+ where
+ P: Unpin,
+ {
+ Pin { pointer }
+ }
+}
+
+struct PhantomPinned;
+impl !Unpin for PhantomPinned {}
+
+struct PinnedStruct {
+ _marker: PhantomPinned,
+}
+
+struct NormalStruct;
+
+fn main() {
+ let _ = Pin::new(NormalStruct);
+
+ let pinned = PinnedStruct { _marker: PhantomPinned };
+ let _ = Pin::new(pinned); // { dg-error "bounds not satisfied for
PinnedStruct .Unpin. is not satisfied .E0277." }
+}
--
2.54.0