]> git.lizzy.rs Git - rust.git/commitdiff
Fallout: btree. Rephrase invariant lifetime in terms of PhantomData.
authorNiko Matsakis <niko@alum.mit.edu>
Thu, 12 Feb 2015 15:33:53 +0000 (10:33 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Feb 2015 15:25:12 +0000 (10:25 -0500)
src/libcollections/btree/map.rs

index 747211e923859df6d1fbab7b13bfb3716f56afa9..f0e558e6f9105afaa8ed8c88e115f14540774ef8 100644 (file)
@@ -512,13 +512,22 @@ mod stack {
     use super::super::node::handle;
     use vec::Vec;
 
+    struct InvariantLifetime<'id>(
+        marker::PhantomData<::core::cell::Cell<&'id ()>>);
+
+    impl<'id> InvariantLifetime<'id> {
+        fn new() -> InvariantLifetime<'id> {
+            InvariantLifetime(marker::PhantomData)
+        }
+    }
+
     /// A generic mutable reference, identical to `&mut` except for the fact that its lifetime
     /// parameter is invariant. This means that wherever an `IdRef` is expected, only an `IdRef`
     /// with the exact requested lifetime can be used. This is in contrast to normal references,
     /// where `&'static` can be used in any function expecting any lifetime reference.
     pub struct IdRef<'id, T: 'id> {
         inner: &'id mut T,
-        marker: marker::InvariantLifetime<'id>
+        _marker: InvariantLifetime<'id>,
     }
 
     impl<'id, T> Deref for IdRef<'id, T> {
@@ -560,7 +569,7 @@ pub struct SearchStack<'a, K:'a, V:'a, Type, NodeType> {
     pub struct Pusher<'id, 'a, K:'a, V:'a> {
         map: &'a mut BTreeMap<K, V>,
         stack: Stack<K, V>,
-        marker: marker::InvariantLifetime<'id>
+        _marker: InvariantLifetime<'id>,
     }
 
     impl<'a, K, V> PartialSearchStack<'a, K, V> {
@@ -595,11 +604,11 @@ pub fn with<T, F: for<'id> FnOnce(Pusher<'id, 'a, K, V>,
             let pusher = Pusher {
                 map: self.map,
                 stack: self.stack,
-                marker: marker::InvariantLifetime
+                _marker: InvariantLifetime::new(),
             };
             let node = IdRef {
                 inner: unsafe { &mut *self.next },
-                marker: marker::InvariantLifetime
+                _marker: InvariantLifetime::new(),
             };
 
             closure(pusher, node)