https://gcc.gnu.org/g:df73ffdeb7e0152ae5efe7554adc9e2834a34798
commit r17-4099-gdf73ffdeb7e0152ae5efe7554adc9e2834a34798 Author: Enes Cevik <[email protected]> Date: Thu Jul 16 12:19:03 2026 +0300 gccrs: lang: Add pin and unpin 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]> Diff: --- 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(+) diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc index b00ce99035b8..5a3e939f93a4 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 1333138265ba..766b47c79464 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 000000000000..dac96fe6c2a9 --- /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." } +}
