Skip to content

Commit bb44764

Browse files
committed
lang: Add pin and unpin
This patch adds pin/unpin lang items to the compiler but not fully tested due to issues #4709 and #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 <enes@nsvke.com>
1 parent 12c9935 commit bb44764

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎gcc/rust/util/rust-lang-item.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ const BiMap<std::string, LangItem::Kind> Rust::LangItem::lang_items = {{
144144
{"generator_state", Kind::GENERATOR_STATE},
145145

146146
{"va_list", Kind::VA_LIST},
147+
{"pin", Kind::PIN},
148+
{"unpin", Kind::UNPIN},
147149
}};
148150

149151
tl::optional<LangItem::Kind>

‎gcc/rust/util/rust-lang-item.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class LangItem
180180
GENERATOR_STATE,
181181

182182
VA_LIST,
183+
PIN,
184+
UNPIN,
183185
};
184186

185187
static const BiMap<std::string, Kind> lang_items;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(no_core, lang_items, optin_builtin_traits, negative_impls)]
2+
#![no_core]
3+
4+
#[lang = "sized"]
5+
pub trait Sized {}
6+
7+
#[lang = "unpin"]
8+
pub auto trait Unpin {}
9+
10+
#[lang = "pin"]
11+
pub struct Pin<P> {
12+
pointer: P,
13+
}
14+
15+
impl<P> Pin<P> {
16+
pub fn new(pointer: P) -> Pin<P>
17+
where
18+
P: Unpin,
19+
{
20+
Pin { pointer }
21+
}
22+
}
23+
24+
struct PhantomPinned;
25+
impl !Unpin for PhantomPinned {}
26+
27+
struct PinnedStruct {
28+
_marker: PhantomPinned,
29+
}
30+
31+
struct NormalStruct;
32+
33+
fn main() {
34+
let _ = Pin::new(NormalStruct);
35+
36+
let pinned = PinnedStruct { _marker: PhantomPinned };
37+
let _ = Pin::new(pinned); // { dg-error "bounds not satisfied for PinnedStruct .Unpin. is not satisfied .E0277." }
38+
}

0 commit comments

Comments
 (0)