Skip to content

Commit 6984395

Browse files
committed
Check if test passes on macOS
1 parent 0191e68 commit 6984395

3 files changed

Lines changed: 50 additions & 7 deletions

File tree

tests/unit/out/refcount/redundant_copy_in_conversion.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9+
pub fn sink_0(it: RefcountMapIter<i32, i32>) -> i32 {
10+
let it: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new(it));
11+
let cit: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new((*it.borrow()).clone()));
12+
return if (*cit.borrow()) == (*it.borrow()).clone() {
13+
(*(*it.borrow()).second().borrow())
14+
} else {
15+
0
16+
};
17+
}
918
pub fn main() {
1019
std::process::exit(main_0());
1120
}
@@ -21,12 +30,26 @@ fn main_0() -> i32 {
2130
let end: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new(RefcountMapIter::end(
2231
(m.as_pointer() as Ptr<BTreeMap<i32, Value<i32>>>),
2332
)));
24-
let const_it: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new(
25-
RefcountMapIter::find_key((m.as_pointer() as Ptr<BTreeMap<i32, Value<i32>>>), &0),
33+
let it0: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new(RefcountMapIter::find_key(
34+
(m.as_pointer() as Ptr<BTreeMap<i32, Value<i32>>>),
35+
&0,
36+
)));
37+
let const_it: Value<RefcountMapIter<i32, i32>> = Rc::new(RefCell::new((*it0.borrow()).clone()));
38+
let r: Value<i32> = Rc::new(RefCell::new(
39+
if (*const_it.borrow()) == (*end.borrow()).clone() {
40+
0
41+
} else {
42+
1
43+
},
2644
));
27-
return if (*const_it.borrow()) == (*end.borrow()) {
45+
(*r.borrow_mut()) += ({
46+
let _it: RefcountMapIter<i32, i32> = (*it0.borrow()).clone();
47+
sink_0(_it)
48+
});
49+
(*r.borrow_mut()) += if (*end.borrow()) == (*end.borrow()) {
2850
0
2951
} else {
3052
1
3153
};
54+
return (*r.borrow());
3255
}

tests/unit/out/unsafe/redundant_copy_in_conversion.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9+
pub unsafe fn sink_0(mut it: UnsafeMapIterator<i32, i32>) -> i32 {
10+
let mut cit: UnsafeMapIterator<i32, i32> = it.clone();
11+
return if cit == it.clone() { *it.second() } else { 0 };
12+
}
913
pub fn main() {
1014
unsafe {
1115
std::process::exit(main_0() as i32);
@@ -16,7 +20,14 @@ unsafe fn main_0() -> i32 {
1620
(*m.entry(0).or_default().as_mut()) = 1;
1721
let mut end: UnsafeMapIterator<i32, i32> =
1822
UnsafeMapIterator::end(&m as *const BTreeMap<i32, Box<i32>>);
19-
let mut const_it: UnsafeMapIterator<i32, i32> =
23+
let mut it0: UnsafeMapIterator<i32, i32> =
2024
UnsafeMapIterator::find_key(&m as *const BTreeMap<i32, Box<i32>>, &0);
21-
return if const_it == end { 0 } else { 1 };
25+
let mut const_it: UnsafeMapIterator<i32, i32> = it0.clone();
26+
let mut r: i32 = if const_it == end.clone() { 0 } else { 1 };
27+
r += (unsafe {
28+
let _it: UnsafeMapIterator<i32, i32> = it0.clone();
29+
sink_0(_it)
30+
});
31+
r += if end == end { 0 } else { 1 };
32+
return r;
2233
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#include <map>
22

3+
static int sink(std::map<int, int>::iterator it) {
4+
std::map<int, int>::const_iterator cit(it);
5+
return cit == it ? it->second : 0;
6+
}
7+
38
int main() {
49
std::map<int, int> m;
510
m[0] = 1;
611
std::map<int, int>::iterator end = m.end();
7-
std::map<int, int>::const_iterator const_it = m.find(0);
12+
std::map<int, int>::iterator it0 = m.find(0);
13+
std::map<int, int>::const_iterator const_it = it0;
814
// Comparing const_iterator with iterator forces an implicit conversion of
915
// `end` to const_iterator. The AST shape differs between platforms:
1016
//
@@ -13,5 +19,8 @@ int main() {
1319
//
1420
// The extra inner CopyCtor on macOS would emit a redundant .clone() in the
1521
// generated Rust. cpp2rust suppresses it so the output matches Linux.
16-
return const_it == end ? 0 : 1;
22+
int r = const_it == end ? 0 : 1;
23+
r += sink(it0);
24+
r += end == end ? 0 : 1;
25+
return r;
1726
}

0 commit comments

Comments
 (0)