Skip to content

Commit d0aefef

Browse files
committed
Add test that passes &AtomicRefCell<T> and AtomicRef<'_, T> to a
function where the `AtomicRef` is dropped and a new borrow is taken from the cell to catch potential UB in this scenario using Miri.
1 parent ade031d commit d0aefef

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/basic.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ fn try_interleaved() {
8484
}
8585
}
8686

87+
// For Miri to catch issues when calling a function.
88+
//
89+
// See how this scenerio affects std::cell::RefCell implementation:
90+
// https://github.com/rust-lang/rust/issues/63787
91+
//
92+
// Also see relevant unsafe code guidelines issue:
93+
// https://github.com/rust-lang/unsafe-code-guidelines/issues/125
94+
#[test]
95+
fn drop_and_borrow_in_fn_call() {
96+
fn drop_and_borrow(cell: &AtomicRefCell<Bar>, borrow: AtomicRef<'_, Bar>) {
97+
drop(borrow);
98+
*cell.borrow_mut() = Bar::default();
99+
}
100+
101+
let a = AtomicRefCell::new(Bar::default());
102+
let borrow = a.borrow();
103+
drop_and_borrow(&a, borrow);
104+
}
105+
87106
#[test]
88107
#[should_panic(expected = "already immutably borrowed")]
89108
fn immutable_then_mutable() {

0 commit comments

Comments
 (0)