Skip to content

Commit

Permalink
Add test that passes &AtomicRefCell<T> and AtomicRef<'_, T> to a
Browse files Browse the repository at this point in the history
function where the `AtomicRef` is dropped and a new borrow is taken from
the cell to catch potential UB in this scenario using Miri.
  • Loading branch information
Imberflur committed Feb 4, 2023
1 parent ade031d commit d0aefef
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ fn try_interleaved() {
}
}

// For Miri to catch issues when calling a function.
//
// See how this scenerio affects std::cell::RefCell implementation:
// https://github.com/rust-lang/rust/issues/63787
//
// Also see relevant unsafe code guidelines issue:
// https://github.com/rust-lang/unsafe-code-guidelines/issues/125
#[test]
fn drop_and_borrow_in_fn_call() {
fn drop_and_borrow(cell: &AtomicRefCell<Bar>, borrow: AtomicRef<'_, Bar>) {
drop(borrow);
*cell.borrow_mut() = Bar::default();
}

let a = AtomicRefCell::new(Bar::default());
let borrow = a.borrow();
drop_and_borrow(&a, borrow);
}

#[test]
#[should_panic(expected = "already immutably borrowed")]
fn immutable_then_mutable() {
Expand Down

0 comments on commit d0aefef

Please sign in to comment.