From 01cc510fb13460c653db6c92ff63f82f95977309 Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Thu, 25 Apr 2024 12:03:57 -0400 Subject: [PATCH] test: add case for borrow extend across scopes --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 53eb742..1f509db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,6 +187,25 @@ mod tests { use super::*; + #[test] + fn test_owned_ref_cell_extend_borrow_across_scopes() { + let cell = OwnedRefCell::new(10); + + // Function that extends the mutable borrow across its original scope + fn extend_borrow(mut borrow: OwnedRefMut, modifier: T) -> OwnedRefMut + where + T: std::ops::AddAssign, + { + *borrow += modifier; + borrow + } + + let borrow_mut = cell.borrow_mut(); + let extended_borrow = extend_borrow(borrow_mut, 5); + + assert_eq!(*extended_borrow, 15); + } + #[test] fn borrow_mut_modify_and_borrow_after_drop() { let cell = OwnedRefCell::new(10);