Fix empty borrow location warnings (#4593)
* Fix empty borrow location warnings * add error tests for rc variants * fix clippy
This commit is contained in:
1 parent
525c00ddac
commit
f95d8e4682
3 files changed
+146
-34
No files matched your search
@@ -33,6 +33,18 @@ fn create_at_location<S: Storage<i32>>(
|
||||
(value, location)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn create_at_location_rc<S: Storage<i32>>(
|
||||
owner: &Owner<S>,
|
||||
) -> (
|
||||
GenerationalBox<i32, S>,
|
||||
&'static std::panic::Location<'static>,
|
||||
) {
|
||||
let location = std::panic::Location::caller();
|
||||
let value = owner.insert_rc(1);
|
||||
(value, location)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_while_writing_error() {
|
||||
fn read_while_writing_error_test<S: Storage<i32> + 'static>() {
|
||||
@@ -54,6 +66,27 @@ fn read_while_writing_error() {
|
||||
read_while_writing_error_test::<UnsyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_while_writing_error_rc() {
|
||||
fn read_while_writing_error_test<S: Storage<i32> + 'static>() {
|
||||
let owner = S::owner();
|
||||
let value = owner.insert_rc(1);
|
||||
|
||||
let (write, location) = write_at_location(value);
|
||||
|
||||
assert_eq!(
|
||||
value.try_read().err(),
|
||||
Some(BorrowError::AlreadyBorrowedMut(
|
||||
AlreadyBorrowedMutError::new(location)
|
||||
))
|
||||
);
|
||||
drop(write);
|
||||
}
|
||||
|
||||
// For sync storage this will deadlock
|
||||
read_while_writing_error_test::<UnsyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_after_dropped_error() {
|
||||
fn read_after_dropped_error_test<S: Storage<i32> + 'static>() {
|
||||
@@ -70,6 +103,22 @@ fn read_after_dropped_error() {
|
||||
read_after_dropped_error_test::<SyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_after_dropped_error_rc() {
|
||||
fn read_after_dropped_error_test<S: Storage<i32> + 'static>() {
|
||||
let owner = S::owner();
|
||||
let (value, location) = create_at_location_rc(&owner);
|
||||
drop(owner);
|
||||
assert_eq!(
|
||||
value.try_read().err(),
|
||||
Some(BorrowError::Dropped(ValueDroppedError::new(location)))
|
||||
);
|
||||
}
|
||||
|
||||
read_after_dropped_error_test::<UnsyncStorage>();
|
||||
read_after_dropped_error_test::<SyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_while_writing_error() {
|
||||
fn write_while_writing_error_test<S: Storage<i32> + 'static>() {
|
||||
@@ -96,6 +145,32 @@ fn write_while_writing_error() {
|
||||
write_while_writing_error_test::<UnsyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_while_writing_error_rc() {
|
||||
fn write_while_writing_error_test<S: Storage<i32> + 'static>() {
|
||||
let owner = S::owner();
|
||||
let value = owner.insert_rc(1);
|
||||
|
||||
#[allow(unused)]
|
||||
let (write, location) = write_at_location(value);
|
||||
|
||||
let write_result = value.try_write();
|
||||
assert!(write_result.is_err());
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
assert_eq!(
|
||||
write_result.err(),
|
||||
Some(BorrowMutError::AlreadyBorrowedMut(
|
||||
AlreadyBorrowedMutError::new(location)
|
||||
))
|
||||
);
|
||||
|
||||
drop(write);
|
||||
}
|
||||
|
||||
// For sync storage this will deadlock
|
||||
write_while_writing_error_test::<UnsyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_while_reading_error() {
|
||||
fn write_while_reading_error_test<S: Storage<i32> + 'static>() {
|
||||
@@ -117,3 +192,25 @@ fn write_while_reading_error() {
|
||||
// For sync storage this will deadlock
|
||||
write_while_reading_error_test::<UnsyncStorage>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_while_reading_error_rc() {
|
||||
fn write_while_reading_error_test<S: Storage<i32> + 'static>() {
|
||||
let owner = S::owner();
|
||||
let value = owner.insert_rc(1);
|
||||
|
||||
let (read, location) = read_at_location(value);
|
||||
|
||||
assert_eq!(
|
||||
value.try_write().err(),
|
||||
Some(BorrowMutError::AlreadyBorrowed(AlreadyBorrowedError::new(
|
||||
vec![location]
|
||||
)))
|
||||
);
|
||||
|
||||
drop(read);
|
||||
}
|
||||
|
||||
// For sync storage this will deadlock
|
||||
write_while_reading_error_test::<UnsyncStorage>();
|
||||
}
|
||||
Reference in new issue
Block a user