Skip to content

Commit b3c00a6

Browse files
committed
Fallout: btree. Rephrase invariant lifetime in terms of PhantomData.
1 parent c5579ca commit b3c00a6

File tree

1 file changed

+13
-4
lines changed
  • src/libcollections/btree

1 file changed

+13
-4
lines changed

src/libcollections/btree/map.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,22 @@ mod stack {
512512
use super::super::node::handle;
513513
use vec::Vec;
514514

515+
struct InvariantLifetime<'id>(
516+
marker::PhantomData<::core::cell::Cell<&'id ()>>);
517+
518+
impl<'id> InvariantLifetime<'id> {
519+
fn new() -> InvariantLifetime<'id> {
520+
InvariantLifetime(marker::PhantomData)
521+
}
522+
}
523+
515524
/// A generic mutable reference, identical to `&mut` except for the fact that its lifetime
516525
/// parameter is invariant. This means that wherever an `IdRef` is expected, only an `IdRef`
517526
/// with the exact requested lifetime can be used. This is in contrast to normal references,
518527
/// where `&'static` can be used in any function expecting any lifetime reference.
519528
pub struct IdRef<'id, T: 'id> {
520529
inner: &'id mut T,
521-
marker: marker::InvariantLifetime<'id>
530+
_marker: InvariantLifetime<'id>,
522531
}
523532

524533
impl<'id, T> Deref for IdRef<'id, T> {
@@ -560,7 +569,7 @@ mod stack {
560569
pub struct Pusher<'id, 'a, K:'a, V:'a> {
561570
map: &'a mut BTreeMap<K, V>,
562571
stack: Stack<K, V>,
563-
marker: marker::InvariantLifetime<'id>
572+
_marker: InvariantLifetime<'id>,
564573
}
565574

566575
impl<'a, K, V> PartialSearchStack<'a, K, V> {
@@ -595,11 +604,11 @@ mod stack {
595604
let pusher = Pusher {
596605
map: self.map,
597606
stack: self.stack,
598-
marker: marker::InvariantLifetime
607+
_marker: InvariantLifetime::new(),
599608
};
600609
let node = IdRef {
601610
inner: unsafe { &mut *self.next },
602-
marker: marker::InvariantLifetime
611+
_marker: InvariantLifetime::new(),
603612
};
604613

605614
closure(pusher, node)

0 commit comments

Comments
 (0)