Skip to content

Commit 0191e68

Browse files
committed
Clone iterator
1 parent e571570 commit 0191e68

6 files changed

Lines changed: 56 additions & 26 deletions

File tree

rules/map/ir_refcount.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,27 @@
462462
"f19": {
463463
"body": [
464464
{
465-
"placeholder": {
466-
"arg": 0,
467-
"access": "read"
465+
"method_call": {
466+
"receiver": [
467+
{
468+
"placeholder": {
469+
"arg": 0,
470+
"access": "read"
471+
}
472+
}
473+
],
474+
"body": [
475+
{
476+
"text": ".clone()"
477+
}
478+
]
468479
}
469480
}
470481
],
471482
"generics": {
472-
"T1": [],
483+
"T1": [
484+
"Clone"
485+
],
473486
"T2": []
474487
},
475488
"params": {

rules/map/ir_unsafe.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,27 @@
466466
"f19": {
467467
"body": [
468468
{
469-
"placeholder": {
470-
"arg": 0,
471-
"access": "read"
469+
"method_call": {
470+
"receiver": [
471+
{
472+
"placeholder": {
473+
"arg": 0,
474+
"access": "read"
475+
}
476+
}
477+
],
478+
"body": [
479+
{
480+
"text": ".clone()"
481+
}
482+
]
472483
}
473484
}
474485
],
475486
"generics": {
476-
"T1": [],
487+
"T1": [
488+
"Clone"
489+
],
477490
"T2": []
478491
},
479492
"params": {

rules/map/tgt_refcount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ fn f17<T1: Ord + Clone + 'static, T2: 'static>(
120120
RefcountMapIter::find_key(a0, &a1)
121121
}
122122

123-
fn f19<T1, T2>(a0: RefcountMapIter<T1, T2>) -> RefcountMapIter<T1, T2> {
124-
a0
123+
fn f19<T1: Clone, T2>(a0: RefcountMapIter<T1, T2>) -> RefcountMapIter<T1, T2> {
124+
a0.clone()
125125
}
126126

127127
fn f20<T1: Ord + Clone + 'static, T2: 'static>(a0: RefcountMapIter<T1, T2>) -> Value<T1> {

rules/map/tgt_unsafe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ unsafe fn f17<T1: Ord + Clone, T2>(a0: BTreeMap<T1, Box<T2>>, a1: T1) -> UnsafeM
8383
UnsafeMapIterator::find_key(&a0 as *const BTreeMap<T1, Box<T2>>, &a1)
8484
}
8585

86-
unsafe fn f19<T1, T2>(a0: UnsafeMapIterator<T1, T2>) -> UnsafeMapIterator<T1, T2> {
87-
a0
86+
unsafe fn f19<T1: Clone, T2>(a0: UnsafeMapIterator<T1, T2>) -> UnsafeMapIterator<T1, T2> {
87+
a0.clone()
8888
}
8989

9090
unsafe fn f20<T1: Ord + Clone, T2>(a0: UnsafeMapIterator<T1, T2>) -> *const T1 {

tests/unit/out/refcount/map.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,22 @@ fn main_0() -> i32 {
192192
&1_i16,
193193
)));
194194
let const_it: Value<RefcountMapIter<i16, u32>> = Rc::new(RefCell::new(
195-
RefcountMapIter::find_key((m.as_pointer() as Ptr<BTreeMap<i16, Value<u32>>>), &10_i16),
195+
RefcountMapIter::find_key((m.as_pointer() as Ptr<BTreeMap<i16, Value<u32>>>), &10_i16)
196+
.clone(),
196197
));
197198
let x1: Value<u32> = Rc::new(RefCell::new(if (*it.borrow()) == (*end.borrow()) {
198199
0_u32
199200
} else {
200201
(*(*it.borrow()).second().borrow())
201202
}));
202203
assert!(((*x1.borrow()) == 4_u32));
203-
let x2: Value<u32> = Rc::new(RefCell::new(if (*const_it.borrow()) == (*end.borrow()) {
204-
0_u32
205-
} else {
206-
(*(*const_it.borrow()).second().borrow())
207-
}));
204+
let x2: Value<u32> = Rc::new(RefCell::new(
205+
if (*const_it.borrow()) == (*end.borrow()).clone() {
206+
0_u32
207+
} else {
208+
(*(*const_it.borrow()).second().borrow())
209+
},
210+
));
208211
assert!(((*x2.borrow()) == 0_u32));
209212
let x3: Value<u32> = Rc::new(RefCell::new(
210213
if (*it.borrow())
@@ -218,7 +221,7 @@ fn main_0() -> i32 {
218221
assert!(((*x3.borrow()) == 4_u32));
219222
let x4: Value<u32> = Rc::new(RefCell::new(
220223
if (*const_it.borrow())
221-
== RefcountMapIter::end((m.as_pointer() as Ptr<BTreeMap<i16, Value<u32>>>))
224+
== RefcountMapIter::end((m.as_pointer() as Ptr<BTreeMap<i16, Value<u32>>>)).clone()
222225
{
223226
0_u32
224227
} else {

tests/unit/out/unsafe/map.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ unsafe fn main_0() -> i32 {
5050
let mut it: UnsafeMapIterator<i16, u32> =
5151
UnsafeMapIterator::find_key(&m as *const BTreeMap<i16, Box<u32>>, &1_i16);
5252
let mut const_it: UnsafeMapIterator<i16, u32> =
53-
UnsafeMapIterator::find_key(&m as *const BTreeMap<i16, Box<u32>>, &10_i16);
53+
UnsafeMapIterator::find_key(&m as *const BTreeMap<i16, Box<u32>>, &10_i16).clone();
5454
let mut x1: u32 = if it == end { 0_u32 } else { *it.second() };
5555
assert!(((x1) == (4_u32)));
56-
let mut x2: u32 = if const_it == end {
56+
let mut x2: u32 = if const_it == end.clone() {
5757
0_u32
5858
} else {
5959
*const_it.second()
@@ -65,11 +65,12 @@ unsafe fn main_0() -> i32 {
6565
*it.second()
6666
};
6767
assert!(((x3) == (4_u32)));
68-
let mut x4: u32 = if const_it == UnsafeMapIterator::end(&m as *const BTreeMap<i16, Box<u32>>) {
69-
0_u32
70-
} else {
71-
*const_it.second()
72-
};
68+
let mut x4: u32 =
69+
if const_it == UnsafeMapIterator::end(&m as *const BTreeMap<i16, Box<u32>>).clone() {
70+
0_u32
71+
} else {
72+
*const_it.second()
73+
};
7374
assert!(((x4) == (0_u32)));
7475
(*m.entry(4_i16).or_default().as_mut()) = 5_u32;
7576
let mut it4: UnsafeMapIterator<i16, u32> =

0 commit comments

Comments
 (0)