Skip to content

Commit

Permalink
fix: compile warn & loom test
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Aug 25, 2023
1 parent 77d3110 commit 2605d2a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions y-octo/src/doc/common/somr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl<T> Somr<T> {
}
}

#[allow(dead_code)]
pub fn get_mut(&mut self) -> Option<&mut T> {
if !self.is_owned() || self.dangling() {
return None;
Expand All @@ -132,6 +133,7 @@ impl<T> Somr<T> {
inner.data.as_mut().map(|x| x.get_mut())
}

#[allow(dead_code)]
pub unsafe fn get_mut_from_ref(&self) -> Option<InnerRefMut<T>> {
if !self.is_owned() || self.dangling() {
return None;
Expand Down Expand Up @@ -487,14 +489,16 @@ mod tests {
// This is UB if we didn't use `UnsafeCell` in `Somr`
#[test]
fn test_inner_mut() {
let five = Somr::new(5);
fn add(a: &Somr<i32>, b: &Somr<i32>) {
unsafe { a.get_mut_from_ref() }
.map(|mut x| *x += *b.get().unwrap())
.unwrap();
}
loom_model!({
let five = Somr::new(5);
fn add(a: &Somr<i32>, b: &Somr<i32>) {
unsafe { a.get_mut_from_ref() }
.map(|mut x| *x += *b.get().unwrap())
.unwrap();
}

add(&five, &five);
assert_eq!(five.get().copied().unwrap(), 10);
add(&five, &five);
assert_eq!(five.get().copied().unwrap(), 10);
});
}
}

0 comments on commit 2605d2a

Please sign in to comment.