diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-02-12 10:33:53 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-02-18 10:25:12 -0500 |
| commit | b3c00a69f23b68cba2901eb98b3de7dfc6990396 (patch) | |
| tree | faf3a12ad08cd82d963f2b12b64f2d9815a9aedb /src | |
| parent | c5579ca340b346f1b685887f7784c2e7f2090dcb (diff) | |
| download | rust-b3c00a69f23b68cba2901eb98b3de7dfc6990396.tar.gz rust-b3c00a69f23b68cba2901eb98b3de7dfc6990396.zip | |
Fallout: btree. Rephrase invariant lifetime in terms of PhantomData.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/btree/map.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 747211e9238..f0e558e6f91 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -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 @@ mod stack { 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 @@ mod stack { 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) |
