miri did not like Node::remove. miri was right.

This commit is contained in:
nora 2021-08-08 18:37:42 +02:00
parent 38b85968cf
commit ffde519487
2 changed files with 3 additions and 27 deletions

View file

@ -394,19 +394,6 @@ impl<T> Node<T> {
pub fn replace_value(&mut self, value: T) -> T {
std::mem::replace(&mut self.value, value)
}
/// Removes a value from the List and returns it
pub fn remove(&mut self) -> T {
// SAFETY: All pointers should always be valid
unsafe {
self.next.map(|mut next| next.as_mut().prev = self.prev);
self.prev.map(|mut prev| prev.as_mut().next = self.next);
}
// SAFETY: A reference is always valid and we have the only one now
let node = unsafe { Box::from_raw(self) };
node.value
}
}
fn allocate_nonnull<T>(element: T) -> NonNull<T> {

View file

@ -83,10 +83,11 @@ fn iter_mut() {
#[test]
fn get_large_number() {
let mut list = LinkedList::new();
for i in 0..1000000 {
// i had to make this smaller because of miri
for i in 0..10000 {
list.push_front(i);
}
assert_eq!(list.get(999999), Some(&0));
assert_eq!(list.get(9999), Some(&0));
}
#[test]
@ -120,18 +121,6 @@ fn node_values() {
assert_eq!(*node.get(), 4);
}
#[test]
fn node_removal() {
let mut list = create_list(&[1, 2, 4]);
let node_two = list.front_node_mut().unwrap().next_mut().unwrap();
node_two.replace_value(3);
let three = node_two.remove();
assert_eq!(three, 3);
assert_eq!(list.get_head(), Some(&1));
assert_eq!(list.get_tail(), Some(&4));
assert_eq!(*list.front_node().unwrap().next().unwrap().get(), 4);
}
#[test]
fn list_len() {
let list = create_list(&[1, 2, 3, 4, 5, 6, 7, 8, 9]);