Skip to content

Commit

Permalink
Fix dropping_references warning
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Oct 20, 2023
1 parent 644653b commit 3d876e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed a `dropping_references` warning in `LinearMap`.

### Removed

- [breaking-change] this crate no longer has a Minimum Supported Rust Version (MSRV) guarantee and
Expand Down
31 changes: 21 additions & 10 deletions src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,6 @@ impl<'a, K, V> Clone for Iter<'a, K, V> {
}
}

impl<K, V, const N: usize> Drop for LinearMap<K, V, N> {
fn drop(&mut self) {
// heapless::Vec implements drop right?
drop(&self.buffer);
// original code below
// unsafe { ptr::drop_in_place(self.buffer.as_mut_slice()) }
}
}

pub struct IterMut<'a, K, V> {
iter: slice::IterMut<'a, (K, V)>,
}
Expand Down Expand Up @@ -540,5 +531,25 @@ mod test {
}
}

// TODO: drop test
#[test]
fn drop() {
droppable!();

{
let mut v: LinearMap<i32, Droppable, 2> = LinearMap::new();
v.insert(0, Droppable::new()).ok().unwrap();
v.insert(1, Droppable::new()).ok().unwrap();
v.remove(&1).unwrap();
}

assert_eq!(Droppable::count(), 0);

{
let mut v: LinearMap<i32, Droppable, 2> = LinearMap::new();
v.insert(0, Droppable::new()).ok().unwrap();
v.insert(1, Droppable::new()).ok().unwrap();
}

assert_eq!(Droppable::count(), 0);
}
}

0 comments on commit 3d876e2

Please sign in to comment.