Skip to content

Commit f95e0c2

Browse files
committed
Fix more import_shadowing fallout in collections.
1 parent 5193d54 commit f95e0c2

File tree

4 files changed

+65
-52
lines changed

4 files changed

+65
-52
lines changed

src/libcollections/btree/map.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ pub enum Entry<'a, K:'a, V:'a> {
131131
/// A vacant Entry.
132132
pub struct VacantEntry<'a, K:'a, V:'a> {
133133
key: K,
134-
stack: stack::SearchStack<'a, K, V, node::Edge, node::Leaf>,
134+
stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>,
135135
}
136136

137137
/// An occupied Entry.
138138
pub struct OccupiedEntry<'a, K:'a, V:'a> {
139-
stack: stack::SearchStack<'a, K, V, node::KV, node::LeafOrInternal>,
139+
stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>,
140140
}
141141

142142
impl<K: Ord, V> BTreeMap<K, V> {
@@ -496,7 +496,8 @@ mod stack {
496496
use core::kinds::marker;
497497
use core::mem;
498498
use super::BTreeMap;
499-
use super::super::node::{mod, Node, Fit, Split, KV, Edge, Internal, Leaf, LeafOrInternal};
499+
use super::super::node::{mod, Node, Fit, Split, Internal, Leaf};
500+
use super::super::node::handle;
500501
use vec::Vec;
501502

502503
/// A generic mutable reference, identical to `&mut` except for the fact that its lifetime
@@ -520,7 +521,7 @@ mod stack {
520521
}
521522
}
522523

523-
type StackItem<K, V> = node::Handle<*mut Node<K, V>, Edge, Internal>;
524+
type StackItem<K, V> = node::Handle<*mut Node<K, V>, handle::Edge, handle::Internal>;
524525
type Stack<K, V> = Vec<StackItem<K, V>>;
525526

526527
/// A `PartialSearchStack` handles the construction of a search stack.
@@ -595,7 +596,9 @@ mod stack {
595596
/// Pushes the requested child of the stack's current top on top of the stack. If the child
596597
/// exists, then a new PartialSearchStack is yielded. Otherwise, a VacantSearchStack is
597598
/// yielded.
598-
pub fn push(mut self, mut edge: node::Handle<IdRef<'id, Node<K, V>>, Edge, Internal>)
599+
pub fn push(mut self, mut edge: node::Handle<IdRef<'id, Node<K, V>>,
600+
handle::Edge,
601+
handle::Internal>)
599602
-> PartialSearchStack<'a, K, V> {
600603
self.stack.push(edge.as_raw());
601604
PartialSearchStack {
@@ -617,7 +620,7 @@ mod stack {
617620
}
618621
}
619622

620-
impl<'a, K, V, NodeType> SearchStack<'a, K, V, KV, NodeType> {
623+
impl<'a, K, V, NodeType> SearchStack<'a, K, V, handle::KV, NodeType> {
621624
/// Gets a reference to the value the stack points to.
622625
pub fn peek(&self) -> &V {
623626
unsafe { self.top.from_raw().into_kv().1 }
@@ -640,7 +643,7 @@ mod stack {
640643
}
641644
}
642645

643-
impl<'a, K, V> SearchStack<'a, K, V, KV, Leaf> {
646+
impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::Leaf> {
644647
/// Removes the key and value in the top element of the stack, then handles underflows as
645648
/// described in BTree's pop function.
646649
fn remove_leaf(mut self) -> V {
@@ -686,7 +689,7 @@ mod stack {
686689
}
687690
}
688691

689-
impl<'a, K, V> SearchStack<'a, K, V, KV, LeafOrInternal> {
692+
impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::LeafOrInternal> {
690693
/// Removes the key and value in the top element of the stack, then handles underflows as
691694
/// described in BTree's pop function.
692695
pub fn remove(self) -> V {
@@ -703,7 +706,7 @@ mod stack {
703706
/// leaves the tree in an inconsistent state that must be repaired by the caller by
704707
/// removing the entry in question. Specifically the key-value pair and its successor will
705708
/// become swapped.
706-
fn into_leaf(mut self) -> SearchStack<'a, K, V, KV, Leaf> {
709+
fn into_leaf(mut self) -> SearchStack<'a, K, V, handle::KV, handle::Leaf> {
707710
unsafe {
708711
let mut top_raw = self.top;
709712
let mut top = top_raw.from_raw_mut();
@@ -757,7 +760,7 @@ mod stack {
757760
}
758761
}
759762

760-
impl<'a, K, V> SearchStack<'a, K, V, Edge, Leaf> {
763+
impl<'a, K, V> SearchStack<'a, K, V, handle::Edge, handle::Leaf> {
761764
/// Inserts the key and value into the top element in the stack, and if that node has to
762765
/// split recursively inserts the split contents into the next element stack until
763766
/// splits stop.

src/libcollections/btree/node.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ pub enum InsertionResult<K, V> {
3434
/// Represents the result of a search for a key in a single node
3535
pub enum SearchResult<NodeRef> {
3636
/// The element was found at the given index
37-
Found(Handle<NodeRef, KV, LeafOrInternal>),
37+
Found(Handle<NodeRef, handle::KV, handle::LeafOrInternal>),
3838
/// The element wasn't found, but if it's anywhere, it must be beyond this edge
39-
GoDown(Handle<NodeRef, Edge, LeafOrInternal>),
39+
GoDown(Handle<NodeRef, handle::Edge, handle::LeafOrInternal>),
4040
}
4141

4242
/// A B-Tree Node. We keep keys/edges/values separate to optimize searching for keys.
@@ -494,12 +494,16 @@ pub struct Handle<NodeRef, Type, NodeType> {
494494
index: uint
495495
}
496496

497-
pub enum KV {}
498-
pub enum Edge {}
497+
pub mod handle {
498+
// Handle types.
499+
pub enum KV {}
500+
pub enum Edge {}
499501

500-
pub enum LeafOrInternal {}
501-
pub enum Leaf {}
502-
pub enum Internal {}
502+
// Handle node types.
503+
pub enum LeafOrInternal {}
504+
pub enum Leaf {}
505+
pub enum Internal {}
506+
}
503507

504508
impl<K: Ord, V> Node<K, V> {
505509
/// Searches for the given key in the node. If it finds an exact match,
@@ -625,7 +629,7 @@ impl<K, V, Type, NodeType> Handle<*mut Node<K, V>, Type, NodeType> {
625629
}
626630
}
627631

628-
impl<'a, K: 'a, V: 'a> Handle<&'a Node<K, V>, Edge, Internal> {
632+
impl<'a, K: 'a, V: 'a> Handle<&'a Node<K, V>, handle::Edge, handle::Internal> {
629633
/// Turns the handle into a reference to the edge it points at. This is necessary because the
630634
/// returned pointer has a larger lifetime than what would be returned by `edge` or `edge_mut`,
631635
/// making it more suitable for moving down a chain of nodes.
@@ -636,7 +640,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a Node<K, V>, Edge, Internal> {
636640
}
637641
}
638642

639-
impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, Edge, Internal> {
643+
impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, handle::Edge, handle::Internal> {
640644
/// Turns the handle into a mutable reference to the edge it points at. This is necessary
641645
/// because the returned pointer has a larger lifetime than what would be returned by
642646
/// `edge_mut`, making it more suitable for moving down a chain of nodes.
@@ -647,7 +651,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, Edge, Internal> {
647651
}
648652
}
649653

650-
impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
654+
impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
651655
// This doesn't exist because there are no uses for it,
652656
// but is fine to add, analagous to edge_mut.
653657
//
@@ -657,11 +661,11 @@ impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
657661
}
658662

659663
pub enum ForceResult<NodeRef, Type> {
660-
Leaf(Handle<NodeRef, Type, Leaf>),
661-
Internal(Handle<NodeRef, Type, Internal>)
664+
Leaf(Handle<NodeRef, Type, handle::Leaf>),
665+
Internal(Handle<NodeRef, Type, handle::Internal>)
662666
}
663667

664-
impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, LeafOrInternal> {
668+
impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafOrInternal> {
665669
/// Figure out whether this handle is pointing to something in a leaf node or to something in
666670
/// an internal node, clarifying the type according to the result.
667671
pub fn force(self) -> ForceResult<NodeRef, Type> {
@@ -679,7 +683,7 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, LeafOrInterna
679683
}
680684
}
681685

682-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Leaf> {
686+
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Leaf> {
683687
/// Tries to insert this key-value pair at the given index in this leaf node
684688
/// If the node is full, we have to split it.
685689
///
@@ -711,7 +715,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Leaf> {
711715
}
712716
}
713717

714-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
718+
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
715719
/// Returns a mutable reference to the edge pointed-to by this handle. This should not be
716720
/// confused with `node`, which references the parent node of what is returned here.
717721
pub fn edge_mut(&mut self) -> &mut Node<K, V> {
@@ -794,11 +798,11 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, Edge, Internal> {
794798
}
795799
}
796800

797-
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, Edge, NodeType> {
801+
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, handle::Edge, NodeType> {
798802
/// Gets the handle pointing to the key/value pair just to the left of the pointed-to edge.
799803
/// This is unsafe because the handle might point to the first edge in the node, which has no
800804
/// pair to its left.
801-
unsafe fn left_kv<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, KV, NodeType> {
805+
unsafe fn left_kv<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, handle::KV, NodeType> {
802806
Handle {
803807
node: &mut *self.node,
804808
index: self.index - 1
@@ -808,15 +812,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, Edge, NodeTy
808812
/// Gets the handle pointing to the key/value pair just to the right of the pointed-to edge.
809813
/// This is unsafe because the handle might point to the last edge in the node, which has no
810814
/// pair to its right.
811-
unsafe fn right_kv<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, KV, NodeType> {
815+
unsafe fn right_kv<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, handle::KV, NodeType> {
812816
Handle {
813817
node: &mut *self.node,
814818
index: self.index
815819
}
816820
}
817821
}
818822

819-
impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, KV, NodeType> {
823+
impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, handle::KV, NodeType> {
820824
/// Turns the handle into references to the key and value it points at. This is necessary
821825
/// because the returned pointers have larger lifetimes than what would be returned by `key`
822826
/// or `val`.
@@ -831,7 +835,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, KV, NodeType> {
831835
}
832836
}
833837

834-
impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, KV, NodeType> {
838+
impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, handle::KV, NodeType> {
835839
/// Turns the handle into mutable references to the key and value it points at. This is
836840
/// necessary because the returned pointers have larger lifetimes than what would be returned
837841
/// by `key_mut` or `val_mut`.
@@ -848,15 +852,16 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, KV, NodeType> {
848852
/// Convert this handle into one pointing at the edge immediately to the left of the key/value
849853
/// pair pointed-to by this handle. This is useful because it returns a reference with larger
850854
/// lifetime than `left_edge`.
851-
pub fn into_left_edge(self) -> Handle<&'a mut Node<K, V>, Edge, NodeType> {
855+
pub fn into_left_edge(self) -> Handle<&'a mut Node<K, V>, handle::Edge, NodeType> {
852856
Handle {
853857
node: &mut *self.node,
854858
index: self.index
855859
}
856860
}
857861
}
858862

859-
impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef, KV, NodeType> {
863+
impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
864+
NodeType> {
860865
// These are fine to include, but are currently unneeded.
861866
//
862867
// /// Returns a reference to the key pointed-to by this handle. This doesn't return a
@@ -874,7 +879,8 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef
874879
// }
875880
}
876881

877-
impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<NodeRef, KV, NodeType> {
882+
impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
883+
NodeType> {
878884
/// Returns a mutable reference to the key pointed-to by this handle. This doesn't return a
879885
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
880886
/// handle.
@@ -890,10 +896,10 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<Node
890896
}
891897
}
892898

893-
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, KV, NodeType> {
899+
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, handle::KV, NodeType> {
894900
/// Gets the handle pointing to the edge immediately to the left of the key/value pair pointed
895901
/// to by this handle.
896-
pub fn left_edge<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, Edge, NodeType> {
902+
pub fn left_edge<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, handle::Edge, NodeType> {
897903
Handle {
898904
node: &mut *self.node,
899905
index: self.index
@@ -902,15 +908,15 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, KV, NodeType
902908

903909
/// Gets the handle pointing to the edge immediately to the right of the key/value pair pointed
904910
/// to by this handle.
905-
pub fn right_edge<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, Edge, NodeType> {
911+
pub fn right_edge<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, handle::Edge, NodeType> {
906912
Handle {
907913
node: &mut *self.node,
908914
index: self.index + 1
909915
}
910916
}
911917
}
912918

913-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, KV, Leaf> {
919+
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Leaf> {
914920
/// Removes the key/value pair at the handle's location.
915921
///
916922
/// # Panics (in debug build)
@@ -921,7 +927,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, KV, Leaf> {
921927
}
922928
}
923929

924-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, KV, Internal> {
930+
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Internal> {
925931
/// Steal! Stealing is roughly analogous to a binary tree rotation.
926932
/// In this case, we're "rotating" right.
927933
unsafe fn steal_rightward(&mut self) {
@@ -1004,7 +1010,8 @@ impl<K, V> Node<K, V> {
10041010
/// # Panics (in debug build)
10051011
///
10061012
/// Panics if the given index is out of bounds.
1007-
pub fn kv_handle(&mut self, index: uint) -> Handle<&mut Node<K, V>, KV, LeafOrInternal> {
1013+
pub fn kv_handle(&mut self, index: uint) -> Handle<&mut Node<K, V>, handle::KV,
1014+
handle::LeafOrInternal> {
10081015
// Necessary for correctness, but in a private module
10091016
debug_assert!(index < self.len(), "kv_handle index out of bounds");
10101017
Handle {

src/libcollections/str.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@
5151
5252
#![doc(primitive = "str")]
5353

54-
use core::prelude::*;
55-
5654
pub use self::MaybeOwned::*;
5755
use self::RecompositionState::*;
5856
use self::DecompositionType::*;
5957

6058
use core::borrow::{BorrowFrom, Cow, ToOwned};
59+
use core::clone::Clone;
6160
use core::default::Default;
6261
use core::fmt;
6362
use core::hash;
64-
use core::cmp;
65-
use core::iter::AdditiveIterator;
63+
use core::char::Char;
64+
use core::cmp::{mod, Eq, Equiv, Ord, Ordering, PartialEq, PartialOrd};
65+
use core::iter::{range, AdditiveIterator, Iterator, IteratorExt};
66+
use core::kinds::Sized;
67+
use core::option::Option::{mod, Some, None};
68+
use core::slice::{AsSlice, SliceExt};
6669

6770
use ring_buf::RingBuf;
6871
use string::String;

src/libstd/c_str.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@
6767
//! }
6868
//! ```
6969
70-
use string::String;
71-
use hash;
70+
use core::prelude::*;
71+
use libc;
72+
7273
use fmt;
74+
use hash;
7375
use kinds::marker;
7476
use mem;
75-
use core::prelude::*;
76-
7777
use ptr;
78-
use raw::Slice;
79-
use slice;
78+
use slice::{mod, ImmutableIntSlice};
8079
use str;
81-
use libc;
80+
use string::String;
81+
8282

8383
/// The representation of a C String.
8484
///
@@ -210,7 +210,7 @@ impl CString {
210210
#[inline]
211211
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
212212
unsafe {
213-
mem::transmute(Slice { data: self.buf, len: self.len() + 1 })
213+
slice::from_raw_buf(&self.buf, self.len() + 1).as_unsigned()
214214
}
215215
}
216216

@@ -219,7 +219,7 @@ impl CString {
219219
#[inline]
220220
pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] {
221221
unsafe {
222-
mem::transmute(Slice { data: self.buf, len: self.len() })
222+
slice::from_raw_buf(&self.buf, self.len()).as_unsigned()
223223
}
224224
}
225225

0 commit comments

Comments
 (0)