[fbl][wavl] Remove a useless and incorrect using directive.

There is no real reason for the generic node_state fetcher in WAVL
tree to have a RankType using alias.  In addition, this alias was
incorrect.  It was missing the TagType parameter for the node_state
template which caused it to incorrectly fall back on the default tag.
This would only be caught when attempting to instantiate a tree of
objects which used the ContainableBaseClasses pattern, but no default
WAVLTreeContainable mix-ins.

Also, add new tests which would have caught this in the first place,
and fix an existing test which was broken and caught by the new test
augmentations.

Test: new tests
Change-Id: If7a83d749feeaf16588ad85fc3ad2fb767b95b9c
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/383486
Commit-Queue: John Grossman <johngro@google.com>
Reviewed-by: Nick Maniscalco <maniscalco@google.com>
Testability-Review: Nick Maniscalco <maniscalco@google.com>
diff --git a/zircon/system/ulib/fbl/include/fbl/intrusive_wavl_tree.h b/zircon/system/ulib/fbl/include/fbl/intrusive_wavl_tree.h
index 9c3080f..479a4eb 100644
--- a/zircon/system/ulib/fbl/include/fbl/intrusive_wavl_tree.h
+++ b/zircon/system/ulib/fbl/include/fbl/intrusive_wavl_tree.h
@@ -801,10 +801,6 @@
   struct AddGenericNodeState<BaseNodeTraits,
                              std::enable_if_t<!internal::has_node_state_v<BaseNodeTraits>>>
       : public BaseNodeTraits {
-   private:
-    using RankType = decltype(std::remove_reference_t<decltype(BaseNodeTraits::node_state(
-                                  *std::declval<typename PtrTraits::RawPtrType>()))>::rank_);
-
    public:
     static auto& node_state(typename PtrTraits::RefType obj) {
       return DefaultWAVLTreeTraits<PtrType>::template node_state<TagType>(obj);
diff --git a/zircon/system/ulib/fbl/test/intrusive_container_node_tests.cc b/zircon/system/ulib/fbl/test/intrusive_container_node_tests.cc
index 5b30276..695573b 100644
--- a/zircon/system/ulib/fbl/test/intrusive_container_node_tests.cc
+++ b/zircon/system/ulib/fbl/test/intrusive_container_node_tests.cc
@@ -126,7 +126,7 @@
 
   struct DLL {
     uint32_t a, b, c;
-    fbl::SinglyLinkedListNodeState<DLL*, NodeOptTag2> dll_node_state_;
+    fbl::DoublyLinkedListNodeState<DLL*, NodeOptTag2> dll_node_state_;
     uint32_t d, e, f;
   } test_dll_obj;
 
@@ -136,8 +136,9 @@
   ASSERT_TRUE(Range::Of(FindDLLNode(test_dll_obj)).ContainedBy(Range::Of(test_dll_obj)));
 
   struct WAVL {
+    uintptr_t GetKey() const { return reinterpret_cast<uintptr_t>(this); }
     uint32_t a, b, c;
-    fbl::SinglyLinkedListNodeState<WAVL*, NodeOptTag3> wavl_node_state_;
+    fbl::WAVLTreeNodeState<WAVL*, NodeOptTag3> wavl_node_state_;
     uint32_t d, e, f;
   } test_wavl_obj;
 
@@ -145,6 +146,11 @@
   static_assert(TYPE(FindWAVLNode(test_wavl_obj))::kNodeOptions == NodeOptTag3,
                 "Default traits found the wrong node!");
   ASSERT_TRUE(Range::Of(FindWAVLNode(test_wavl_obj)).ContainedBy(Range::Of(test_wavl_obj)));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::SinglyLinkedList<SLL*> sll;
+  [[maybe_unused]] fbl::DoublyLinkedList<DLL*> dll;
+  [[maybe_unused]] fbl::WAVLTree<uintptr_t, WAVL*> tree;
 }
 
 TEST(IntrusiveContainerNodeTest, DefaultSingleNode) {
@@ -169,6 +175,7 @@
   ASSERT_TRUE(Range::Of(FindDLLNode(test_dll_obj)).ContainedBy(Range::Of(test_dll_obj)));
 
   struct WAVL : public fbl::WAVLTreeContainable<WAVL*, NodeOptTag3> {
+    uintptr_t GetKey() const { return reinterpret_cast<uintptr_t>(this); }
     uint32_t a, b, c;
   } test_wavl_obj;
 
@@ -176,6 +183,11 @@
   static_assert(TYPE(FindWAVLNode(test_wavl_obj))::kNodeOptions == NodeOptTag3,
                 "Default traits found the wrong node!");
   ASSERT_TRUE(Range::Of(FindWAVLNode(test_wavl_obj)).ContainedBy(Range::Of(test_wavl_obj)));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::SinglyLinkedList<SLL*> sll;
+  [[maybe_unused]] fbl::DoublyLinkedList<DLL*> dll;
+  [[maybe_unused]] fbl::WAVLTree<uintptr_t, WAVL*> tree;
 }
 
 TEST(IntrusiveContainerNodeTest, MultipleSLLTaggedNodes) {
@@ -207,6 +219,11 @@
       Range::Of(FindSLLNode<TagType2>(test_sll_obj)),
       Range::Of(FindSLLNode<TagType3>(test_sll_obj)),
   }));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<SLL*, TagType1> list1;
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<SLL*, TagType2> list2;
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<SLL*, TagType3> list3;
 }
 
 TEST(IntrusiveContainerNodeTest, MultipleDLLTaggedNodes) {
@@ -238,6 +255,11 @@
       Range::Of(FindDLLNode<TagType2>(test_dll_obj)),
       Range::Of(FindDLLNode<TagType3>(test_dll_obj)),
   }));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<DLL*, TagType1> list1;
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<DLL*, TagType2> list2;
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<DLL*, TagType3> list3;
 }
 
 TEST(IntrusiveContainerNodeTest, MultipleWAVLTaggedNodes) {
@@ -247,6 +269,7 @@
       : public fbl::ContainableBaseClasses<fbl::WAVLTreeContainable<WAVL*, NodeOptTag1, TagType1>,
                                            fbl::WAVLTreeContainable<WAVL*, NodeOptTag2, TagType2>,
                                            fbl::WAVLTreeContainable<WAVL*, NodeOptTag3, TagType3>> {
+    uintptr_t GetKey() const { return reinterpret_cast<uintptr_t>(this); }
     uint32_t a, b, c;
   } test_wavl_obj;
 
@@ -270,6 +293,11 @@
       Range::Of(FindWAVLNode<TagType2>(test_wavl_obj)),
       Range::Of(FindWAVLNode<TagType3>(test_wavl_obj)),
   }));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, WAVL*, TagType1> tree1;
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, WAVL*, TagType2> tree2;
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, WAVL*, TagType3> tree3;
 }
 
 TEST(IntrusiveContainerNodeTest, MultipleDifferentTaggedNodes) {
@@ -279,6 +307,7 @@
       : public fbl::ContainableBaseClasses<fbl::SinglyLinkedListable<Obj*, NodeOptTag1, TagType1>,
                                            fbl::DoublyLinkedListable<Obj*, NodeOptTag2, TagType2>,
                                            fbl::WAVLTreeContainable<Obj*, NodeOptTag3, TagType3>> {
+    uintptr_t GetKey() const { return reinterpret_cast<uintptr_t>(this); }
     uint32_t a, b, c;
   } test_obj;
 
@@ -313,6 +342,11 @@
   { auto& [[maybe_unused]] node = FindWAVLNode<TagType1>(test_obj); };
   { auto& [[maybe_unused]] node = FindWAVLNode<TagType2>(test_obj); };
 #endif
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<Obj*, TagType1> sll;
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<Obj*, TagType2> dll;
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, Obj*, TagType3> tree;
 }
 
 TEST(IntrusiveContainerNodeTest, MultipleDifferentDefaultNodes) {
@@ -344,6 +378,11 @@
       Range::Of(FindDLLNode(test_obj)),
       Range::Of(FindWAVLNode(test_obj)),
   }));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::SinglyLinkedList<Obj*> sll;
+  [[maybe_unused]] fbl::DoublyLinkedList<Obj*> dll;
+  [[maybe_unused]] fbl::WAVLTree<uintptr_t, Obj*> tree;
 }
 
 TEST(IntrusiveContainerNodeTest, ComplicatedContainables) {
@@ -411,6 +450,19 @@
       Range::Of(FindDLLNode<TagType8>(test_obj)),
       Range::Of(FindWAVLNode<TagType9>(test_obj)),
   }));
+
+  // Make sure that we can instantiate containers which use these nodes.
+  [[maybe_unused]] fbl::SinglyLinkedList<Obj*> default_sll;
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<Obj*, TagType4> sll_tag4;
+  [[maybe_unused]] fbl::TaggedSinglyLinkedList<Obj*, TagType7> sll_tag7;
+
+  [[maybe_unused]] fbl::DoublyLinkedList<Obj*> default_dll;
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<Obj*, TagType5> dll_tag5;
+  [[maybe_unused]] fbl::TaggedDoublyLinkedList<Obj*, TagType8> dll_tag8;
+
+  [[maybe_unused]] fbl::WAVLTree<uintptr_t, Obj*> default_tree;
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, Obj*, TagType6> tree_tag6;
+  [[maybe_unused]] fbl::TaggedWAVLTree<uintptr_t, Obj*, TagType9> tree_tag9;
 }
 
 TEST(IntrusiveContainerNodeTest, ContainerNodeTypeMatches) {