]> git.lizzy.rs Git - rust.git/commitdiff
Check tail node in check_links
authorJohn-John Tedro <udoprog@tedro.se>
Sat, 25 Nov 2017 23:30:33 +0000 (00:30 +0100)
committerJohn-John Tedro <udoprog@tedro.se>
Sat, 25 Nov 2017 23:30:33 +0000 (00:30 +0100)
src/liballoc/linked_list.rs

index fac6acaca6125aa80b3882ac450a826b90646980..99ad424cc20b78b57a9002cacea8a9d1f94fbe36 100644 (file)
@@ -1288,6 +1288,8 @@ pub fn check_links<T>(list: &LinkedList<T>) {
             let mut node_ptr: &Node<T>;
             match list.head {
                 None => {
+                    // tail node should also be None.
+                    assert!(list.tail.is_none());
                     assert_eq!(0, list.len);
                     return;
                 }
@@ -1314,6 +1316,11 @@ pub fn check_links<T>(list: &LinkedList<T>) {
                     }
                 }
             }
+
+            // verify that the tail node points to the last node.
+            let tail = list.tail.as_ref().expect("some tail node").as_ref();
+            assert_eq!(tail as *const Node<T>, node_ptr as *const Node<T>);
+            // check that len matches interior links.
             assert_eq!(len, list.len);
         }
     }