Skip to content

Commit 5194926

Browse files
authored
Add refcount rules for std::array size and copy construction (#596)
1 parent 0b99110 commit 5194926

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎rules/array/tgt_refcount.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn f1<T1>(a0: Ptr<T1>) -> Ptr<T1> {
2121
a0
2222
}
2323

24+
fn f2<T1, const T2: usize>(a0: Ptr<T1>) -> usize {
25+
T2
26+
}
27+
2428
fn f3<T1>(a0: Ptr<T1>) -> Ptr<T1> {
2529
a0
2630
}
@@ -35,6 +39,10 @@ fn f5<T1: MoveAssign, const T2: usize>(a0: Ptr<T1>, a1: Ptr<T1>) {
3539
}
3640
}
3741

42+
fn f6<T1: Clone + ByteRepr, const T2: usize>(a0: Ptr<T1>) -> Box<[T1]> {
43+
(0..T2).map(|__i| a0.read_at(__i)).collect()
44+
}
45+
3846
fn f7<T1: CopyAssign, const T2: usize>(a0: Ptr<T1>, a1: Ptr<T1>) {
3947
for __i in 0..T2 {
4048
T1::copy_assign(&a0.offset(__i), a1.offset(__i));

‎tests/unit/inline_container_fields.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int main() {
131131
assert(moves == 3 && copies == 0 && cb[1].v == 5 && ca[1].v == -1);
132132
std::array<Counted, 3> cc(cb);
133133
assert(copies == 3 && cc[1].v == 5 && cb[1].v == 5);
134+
assert(cc.size() == 3);
134135
cc[2].v = 8;
135136
cb = cc;
136137
assert(copy_assigns == 3 && move_assigns == 0 && cb[2].v == 8);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,16 @@ fn main_0() -> i32 {
366366
&& ({ (*ca.borrow())[1_usize].v } == -1_i32)
367367
})
368368
);
369-
let cc: Value<Box<[Counted]>> = Rc::new(RefCell::new((*cb.borrow()).clone()));
369+
let cc: Value<Box<[Counted]>> = Rc::new(RefCell::new(
370+
(0..3).map(|__i| cb.decay().read_at(__i)).collect(),
371+
));
370372
assert!(
371373
({
372374
((copies_2.with(|rc| *rc.borrow()) == 3) && ({ (*cc.borrow())[1_usize].v } == 5))
373375
&& ({ (*cb.borrow())[1_usize].v } == 5)
374376
})
375377
);
378+
assert!((3 == 3_usize));
376379
(*cc.borrow_mut())[2_usize].v = 8;
377380
for __i in 0..3 {
378381
&cb.decay().offset(__i).copy_assign(cc.decay().offset(__i));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ unsafe fn main_0() -> i32 {
284284
&& ((cc[(1_usize)].v) == (5)))
285285
&& ((cb[(1_usize)].v) == (5))
286286
);
287+
assert!(((3) == (3_usize)));
287288
cc[(2_usize)].v = 8;
288289
for __i in 0..3 {
289290
(*&mut cb[__i]).copy_assign(&cc[__i]);

0 commit comments

Comments
 (0)