@@ -668,7 +668,8 @@ impl<K: Ord, V> TreeMap<K, V> {
668668 }
669669}
670670
671- /// A lazy forward iterator over a map.
671+ /// Note: stage0-specific version that lacks bound on A.
672+ #[ cfg( stage0) ]
672673pub struct Entries < ' a , K , V > {
673674 stack : Vec < & ' a TreeNode < K , V > > ,
674675 // See the comment on MutEntries; this is just to allow
@@ -679,13 +680,32 @@ pub struct Entries<'a, K, V> {
679680 remaining_max : uint
680681}
681682
682- /// Lazy backward iterator over a map.
683+ /// Lazy forward iterator over a map
684+ #[ cfg( not( stage0) ) ]
685+ pub struct Entries < ' a , K : ' a , V : ' a > {
686+ stack : Vec < & ' a TreeNode < K , V > > ,
687+ // See the comment on MutEntries; this is just to allow
688+ // code-sharing (for this immutable-values iterator it *could* very
689+ // well be Option<&'a TreeNode<K,V>>).
690+ node : * const TreeNode < K , V > ,
691+ remaining_min : uint ,
692+ remaining_max : uint
693+ }
694+
695+ /// Note: stage0-specific version that lacks bound on A.
696+ #[ cfg( stage0) ]
683697pub struct RevEntries < ' a , K , V > {
684698 iter : Entries < ' a , K , V > ,
685699}
686700
687- /// A lazy forward iterator over a map that allows for the mutation of
688- /// the values.
701+ /// Lazy backward iterator over a map
702+ #[ cfg( not( stage0) ) ]
703+ pub struct RevEntries < ' a , K : ' a , V : ' a > {
704+ iter : Entries < ' a , K , V > ,
705+ }
706+
707+ /// Note: stage0-specific version that lacks bound on A.
708+ #[ cfg( stage0) ]
689709pub struct MutEntries < ' a , K , V > {
690710 stack : Vec < & ' a mut TreeNode < K , V > > ,
691711 // Unfortunately, we require some unsafe-ness to get around the
@@ -712,11 +732,46 @@ pub struct MutEntries<'a, K, V> {
712732 remaining_max : uint
713733}
714734
715- /// Lazy backward iterator over a map.
735+ /// Lazy forward iterator over a map that allows for the mutation of
736+ /// the values.
737+ #[ cfg( not( stage0) ) ]
738+ pub struct MutEntries < ' a , K : ' a , V : ' a > {
739+ stack : Vec < & ' a mut TreeNode < K , V > > ,
740+ // Unfortunately, we require some unsafe-ness to get around the
741+ // fact that we would be storing a reference *into* one of the
742+ // nodes in the stack.
743+ //
744+ // As far as the compiler knows, this would let us invalidate the
745+ // reference by assigning a new value to this node's position in
746+ // its parent, which would cause this current one to be
747+ // deallocated so this reference would be invalid. (i.e. the
748+ // compilers complaints are 100% correct.)
749+ //
750+ // However, as far as you humans reading this code know (or are
751+ // about to know, if you haven't read far enough down yet), we are
752+ // only reading from the TreeNode.{left,right} fields. the only
753+ // thing that is ever mutated is the .value field (although any
754+ // actual mutation that happens is done externally, by the
755+ // iterator consumer). So, don't be so concerned, rustc, we've got
756+ // it under control.
757+ //
758+ // (This field can legitimately be null.)
759+ node : * mut TreeNode < K , V > ,
760+ remaining_min : uint ,
761+ remaining_max : uint
762+ }
763+
764+ /// Note: stage0-specific version that lacks bound on A.
765+ #[ cfg( stage0) ]
716766pub struct RevMutEntries < ' a , K , V > {
717767 iter : MutEntries < ' a , K , V > ,
718768}
719769
770+ /// Lazy backward iterator over a map
771+ #[ cfg( not( stage0) ) ]
772+ pub struct RevMutEntries < ' a , K : ' a , V : ' a > {
773+ iter : MutEntries < ' a , K , V > ,
774+ }
720775
721776/// TreeMap keys iterator.
722777pub type Keys < ' a , K , V > =
@@ -885,9 +940,7 @@ fn mut_deref<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
885940 }
886941}
887942
888-
889-
890- /// A lazy forward iterator over a map that consumes the map while iterating.
943+ /// Lazy forward iterator over a map that consumes the map while iterating
891944pub struct MoveEntries < K , V > {
892945 stack : Vec < TreeNode < K , V > > ,
893946 remaining : uint
@@ -1322,45 +1375,90 @@ impl<T: Ord> TreeSet<T> {
13221375 }
13231376}
13241377
1325- /// A lazy forward iterator over a set.
1378+ /// Note: stage0-specific version that lacks bound on A.
1379+ #[ cfg( stage0) ]
13261380pub struct SetItems < ' a , T > {
13271381 iter : Entries < ' a , T , ( ) >
13281382}
13291383
1330- /// Lazy backward iterator over a set.
1384+ /// A lazy forward iterator over a set.
1385+ #[ cfg( not( stage0) ) ]
1386+ pub struct SetItems < ' a , T : ' a > {
1387+ iter : Entries < ' a , T , ( ) >
1388+ }
1389+
1390+ /// Note: stage0-specific version that lacks bound on A.
1391+ #[ cfg( stage0) ]
13311392pub struct RevSetItems < ' a , T > {
13321393 iter : RevEntries < ' a , T , ( ) >
13331394}
13341395
1396+ /// A lazy backward iterator over a set.
1397+ #[ cfg( not( stage0) ) ]
1398+ pub struct RevSetItems < ' a , T : ' a > {
1399+ iter : RevEntries < ' a , T , ( ) >
1400+ }
1401+
13351402/// A lazy forward iterator over a set that consumes the set while iterating.
13361403pub type MoveSetItems < T > = iter:: Map < ' static , ( T , ( ) ) , T , MoveEntries < T , ( ) > > ;
13371404
1338- /// A lazy iterator producing elements in the set difference (in-order).
1405+ /// Note: stage0-specific version that lacks bound on A.
1406+ #[ cfg( stage0) ]
13391407pub struct DifferenceItems < ' a , T > {
13401408 a : Peekable < & ' a T , SetItems < ' a , T > > ,
13411409 b : Peekable < & ' a T , SetItems < ' a , T > > ,
13421410}
13431411
1344- /// A lazy iterator producing elements in the set symmetric difference (in-order).
1412+ /// A lazy iterator producing elements in the set difference (in-order).
1413+ #[ cfg( not( stage0) ) ]
1414+ pub struct DifferenceItems < ' a , T : ' a > {
1415+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1416+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1417+ }
1418+
1419+ /// Note: stage0-specific version that lacks bound on A.
1420+ #[ cfg( stage0) ]
13451421pub struct SymDifferenceItems < ' a , T > {
13461422 a : Peekable < & ' a T , SetItems < ' a , T > > ,
13471423 b : Peekable < & ' a T , SetItems < ' a , T > > ,
13481424}
13491425
1350- /// A lazy iterator producing elements in the set intersection (in-order).
1426+ /// A lazy iterator producing elements in the set symmetric difference (in-order).
1427+ #[ cfg( not( stage0) ) ]
1428+ pub struct SymDifferenceItems < ' a , T : ' a > {
1429+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1430+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1431+ }
1432+
1433+ /// Note: stage0-specific version that lacks bound on A.
1434+ #[ cfg( stage0) ]
13511435pub struct IntersectionItems < ' a , T > {
13521436 a : Peekable < & ' a T , SetItems < ' a , T > > ,
13531437 b : Peekable < & ' a T , SetItems < ' a , T > > ,
13541438}
13551439
1356- /// A lazy iterator producing elements in the set union (in-order).
1440+ /// A lazy iterator producing elements in the set intersection (in-order).
1441+ #[ cfg( not( stage0) ) ]
1442+ pub struct IntersectionItems < ' a , T : ' a > {
1443+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1444+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1445+ }
1446+
1447+ /// Note: stage0-specific version that lacks bound on A.
1448+ #[ cfg( stage0) ]
13571449pub struct UnionItems < ' a , T > {
13581450 a : Peekable < & ' a T , SetItems < ' a , T > > ,
13591451 b : Peekable < & ' a T , SetItems < ' a , T > > ,
13601452}
13611453
1362- /// Compare `x` and `y`, but return `short` if x is None and `long` if y is
1363- /// `None`.
1454+ /// A lazy iterator producing elements in the set union (in-order).
1455+ #[ cfg( not( stage0) ) ]
1456+ pub struct UnionItems < ' a , T : ' a > {
1457+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1458+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1459+ }
1460+
1461+ /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
13641462fn cmp_opt < T : Ord > ( x : Option < & T > , y : Option < & T > ,
13651463 short : Ordering , long : Ordering ) -> Ordering {
13661464 match ( x, y) {
0 commit comments