Skip to content

Commit c163a74

Browse files
committed
add test with an Rc cycle to create a memleak
1 parent c26af36 commit c163a74

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/compile-fail/memleak_rc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//error-pattern: the evaluated program leaked memory
2+
3+
use std::rc::Rc;
4+
use std::cell::RefCell;
5+
6+
struct Dummy(Rc<RefCell<Option<Dummy>>>);
7+
8+
fn main() {
9+
let x = Dummy(Rc::new(RefCell::new(None)));
10+
let y = Dummy(x.0.clone());
11+
*x.0.borrow_mut() = Some(y);
12+
}

0 commit comments

Comments
 (0)