Skip to content

Commit 0bc8ba0

Browse files
committed
Don't genrate traits for non-instantiated methods
1 parent 65c94a2 commit 0bc8ba0

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎tests/unit/operator_traits.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ struct Free {
2727
bool operator<(const Free &a, const Free &b) { return a.v < b.v; }
2828
bool operator==(const Free &a, const Free &b) { return a.v == b.v; }
2929

30+
template <class T> struct Wrapped {
31+
T v;
32+
friend bool operator==(const Wrapped &a, const Wrapped &b) {
33+
return a.v == b.v;
34+
}
35+
friend bool operator<(const Wrapped &a, const Wrapped &b) {
36+
return a.v < b.v;
37+
}
38+
};
39+
3040
int main() {
41+
Wrapped<int> w{2};
42+
assert(w.v == 2);
43+
3144
std::vector<Lt> lts{{3}, {1}, {2}};
3245
std::sort(lts.begin(), lts.end());
3346
assert(lts[0].v == 1 && lts[1].v == 2 && lts[2].v == 3);

‎tests/unit/out/refcount/operator_traits.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,40 @@ pub fn operator_eq_1(a: Ptr<Free>, b: Ptr<Free>) -> bool {
232232
_lhs == (*(*b.upgrade().deref()).v.borrow())
233233
};
234234
}
235+
#[derive(Default)]
236+
pub struct Wrapped_int_ {
237+
pub v: Value<i32>,
238+
}
239+
impl Clone for Wrapped_int_ {
240+
fn clone(&self) -> Self {
241+
let __this: Value<Wrapped_int_> = Rc::new(RefCell::new(Self {
242+
v: Rc::new(RefCell::new((*self.v.borrow()))),
243+
}));
244+
let this: Ptr<Wrapped_int_> = __this.as_pointer();
245+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
246+
}
247+
}
248+
impl ByteRepr for Wrapped_int_ {
249+
fn byte_size() -> usize {
250+
4
251+
}
252+
fn to_bytes(&self, buf: &mut [u8]) {
253+
(*self.v.borrow()).to_bytes(&mut buf[0..4]);
254+
}
255+
fn from_bytes(buf: &[u8]) -> Self {
256+
Self {
257+
v: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
258+
}
259+
}
260+
}
235261
pub fn main() {
236262
std::process::exit(main_0());
237263
}
238264
fn main_0() -> i32 {
265+
let w: Value<Wrapped_int_> = Rc::new(RefCell::new(Wrapped_int_ {
266+
v: Rc::new(RefCell::new(2)),
267+
}));
268+
assert!(((*(*w.borrow()).v.borrow()) == 2));
239269
let lts: Value<Vec<Lt>> = Rc::new(RefCell::new(vec![
240270
Lt {
241271
v: Rc::new(RefCell::new(3)),

‎tests/unit/out/unsafe/operator_traits.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,19 @@ pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool {
123123
pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool {
124124
return (((*a).v) == ((*b).v));
125125
}
126+
#[repr(C)]
127+
#[derive(Copy, Clone, Default)]
128+
pub struct Wrapped_int_ {
129+
pub v: i32,
130+
}
126131
pub fn main() {
127132
unsafe {
128133
std::process::exit(main_0() as i32);
129134
}
130135
}
131136
unsafe fn main_0() -> i32 {
137+
let mut w: Wrapped_int_ = Wrapped_int_ { v: 2 };
138+
assert!(((w.v) == (2)));
132139
let mut lts: Vec<Lt> = vec![Lt { v: 3 }, Lt { v: 1 }, Lt { v: 2 }];
133140
{
134141
let len = lts

0 commit comments

Comments
 (0)