Skip to content

Commit 340f3fd

Browse files
committed
rollup merge of #20410: japaric/assoc-types
Conflicts: src/liballoc/lib.rs src/libcollections/lib.rs src/libcollections/slice.rs src/libcore/ops.rs src/libcore/prelude.rs src/libcore/ptr.rs src/librustc/middle/traits/project.rs src/libstd/c_str.rs src/libstd/io/mem.rs src/libstd/io/mod.rs src/libstd/lib.rs src/libstd/path/posix.rs src/libstd/path/windows.rs src/libstd/prelude.rs src/libstd/rt/exclusive.rs src/libsyntax/lib.rs src/test/compile-fail/issue-18566.rs src/test/run-pass/deref-mut-on-ref.rs src/test/run-pass/deref-on-ref.rs src/test/run-pass/dst-deref-mut.rs src/test/run-pass/dst-deref.rs src/test/run-pass/fixup-deref-mut.rs src/test/run-pass/issue-13264.rs src/test/run-pass/overloaded-autoderef-indexing.rs
2 parents 8cf9929 + 1abee08 commit 340f3fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+898
-588
lines changed

src/liballoc/arc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ impl<T> BorrowFrom<Arc<T>> for T {
247247
}
248248

249249
#[experimental = "Deref is experimental."]
250-
impl<T> Deref<T> for Arc<T> {
250+
impl<T> Deref for Arc<T> {
251+
type Target = T;
252+
251253
#[inline]
252254
fn deref(&self) -> &T {
253255
&self.inner().data

src/liballoc/boxed.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ impl fmt::Show for Box<Any> {
155155
}
156156
}
157157

158-
impl<Sized? T> Deref<T> for Box<T> {
158+
impl<Sized? T> Deref for Box<T> {
159+
type Target = T;
160+
159161
fn deref(&self) -> &T { &**self }
160162
}
161163

162-
impl<Sized? T> DerefMut<T> for Box<T> {
164+
impl<Sized? T> DerefMut for Box<T> {
163165
fn deref_mut(&mut self) -> &mut T { &mut **self }
164166
}
165167

@@ -212,7 +214,7 @@ mod test {
212214

213215
#[test]
214216
fn deref() {
215-
fn homura<T: Deref<i32>>(_: T) { }
217+
fn homura<T: Deref<Target=i32>>(_: T) { }
216218
homura(box 765i32);
217219
}
218220
}

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#![no_std]
6767
#![allow(unknown_features)]
6868
#![feature(lang_items, phase, unsafe_destructor, default_type_params, old_orphan_check)]
69+
#![feature(associated_types)]
6970

7071
#[phase(plugin, link)]
7172
extern crate core;

src/liballoc/rc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ impl<T> BorrowFrom<Rc<T>> for T {
355355
}
356356

357357
#[experimental = "Deref is experimental."]
358-
impl<T> Deref<T> for Rc<T> {
358+
impl<T> Deref for Rc<T> {
359+
type Target = T;
360+
359361
#[inline(always)]
360362
fn deref(&self) -> &T {
361363
&self.inner().value

src/libcollections/btree/map.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,15 @@ mod stack {
518518
marker: marker::InvariantLifetime<'id>
519519
}
520520

521-
impl<'id, T> Deref<T> for IdRef<'id, T> {
521+
impl<'id, T> Deref for IdRef<'id, T> {
522+
type Target = T;
523+
522524
fn deref(&self) -> &T {
523525
&*self.inner
524526
}
525527
}
526528

527-
impl<'id, T> DerefMut<T> for IdRef<'id, T> {
529+
impl<'id, T> DerefMut for IdRef<'id, T> {
528530
fn deref_mut(&mut self) -> &mut T {
529531
&mut *self.inner
530532
}

src/libcollections/btree/node.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ impl<K: Clone, V: Clone> Clone for Node<K, V> {
457457
/// flag: &'a Cell<bool>,
458458
/// }
459459
///
460-
/// impl<'a> Deref<Node<uint, uint>> for Nasty<'a> {
460+
/// impl<'a> Deref for Nasty<'a> {
461+
/// type Target = Node<uint, uint>;
462+
///
461463
/// fn deref(&self) -> &Node<uint, uint> {
462464
/// if self.flag.get() {
463465
/// &*self.second
@@ -513,7 +515,7 @@ impl<K: Ord, V> Node<K, V> {
513515
/// Searches for the given key in the node. If it finds an exact match,
514516
/// `Found` will be yielded with the matching index. If it doesn't find an exact match,
515517
/// `GoDown` will be yielded with the index of the subtree the key must lie in.
516-
pub fn search<Sized? Q, NodeRef: Deref<Node<K, V>>>(node: NodeRef, key: &Q)
518+
pub fn search<Sized? Q, NodeRef: Deref<Target=Node<K, V>>>(node: NodeRef, key: &Q)
517519
-> SearchResult<NodeRef> where Q: BorrowFrom<K> + Ord {
518520
// FIXME(Gankro): Tune when to search linear or binary based on B (and maybe K/V).
519521
// For the B configured as of this writing (B = 6), binary search was *significantly*
@@ -590,7 +592,7 @@ impl <K, V> Node<K, V> {
590592
}
591593
}
592594

593-
impl<K, V, NodeRef: Deref<Node<K, V>>, Type, NodeType> Handle<NodeRef, Type, NodeType> {
595+
impl<K, V, NodeRef: Deref<Target=Node<K, V>>, Type, NodeType> Handle<NodeRef, Type, NodeType> {
594596
/// Returns a reference to the node that contains the pointed-to edge or key/value pair. This
595597
/// is very different from `edge` and `edge_mut` because those return children of the node
596598
/// returned by `node`.
@@ -599,7 +601,9 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type, NodeType> Handle<NodeRef, Type, Nod
599601
}
600602
}
601603

602-
impl<K, V, NodeRef: DerefMut<Node<K, V>>, Type, NodeType> Handle<NodeRef, Type, NodeType> {
604+
impl<K, V, NodeRef, Type, NodeType> Handle<NodeRef, Type, NodeType> where
605+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
606+
{
603607
/// Converts a handle into one that stores the same information using a raw pointer. This can
604608
/// be useful in conjunction with `from_raw` when the type system is insufficient for
605609
/// determining the lifetimes of the nodes.
@@ -655,7 +659,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, handle::Edge, handle::Internal
655659
}
656660
}
657661

658-
impl<K, V, NodeRef: Deref<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
662+
impl<K, V, NodeRef: Deref<Target=Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
659663
// This doesn't exist because there are no uses for it,
660664
// but is fine to add, analagous to edge_mut.
661665
//
@@ -669,7 +673,7 @@ pub enum ForceResult<NodeRef, Type> {
669673
Internal(Handle<NodeRef, Type, handle::Internal>)
670674
}
671675

672-
impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafOrInternal> {
676+
impl<K, V, NodeRef: Deref<Target=Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafOrInternal> {
673677
/// Figure out whether this handle is pointing to something in a leaf node or to something in
674678
/// an internal node, clarifying the type according to the result.
675679
pub fn force(self) -> ForceResult<NodeRef, Type> {
@@ -686,8 +690,9 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafO
686690
}
687691
}
688692
}
689-
690-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Leaf> {
693+
impl<K, V, NodeRef> Handle<NodeRef, handle::Edge, handle::Leaf> where
694+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
695+
{
691696
/// Tries to insert this key-value pair at the given index in this leaf node
692697
/// If the node is full, we have to split it.
693698
///
@@ -719,7 +724,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::
719724
}
720725
}
721726

722-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Internal> {
727+
impl<K, V, NodeRef> Handle<NodeRef, handle::Edge, handle::Internal> where
728+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
729+
{
723730
/// Returns a mutable reference to the edge pointed-to by this handle. This should not be
724731
/// confused with `node`, which references the parent node of what is returned here.
725732
pub fn edge_mut(&mut self) -> &mut Node<K, V> {
@@ -802,7 +809,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::
802809
}
803810
}
804811

805-
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, handle::Edge, NodeType> {
812+
impl<K, V, NodeRef, NodeType> Handle<NodeRef, handle::Edge, NodeType> where
813+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
814+
{
806815
/// Gets the handle pointing to the key/value pair just to the left of the pointed-to edge.
807816
/// This is unsafe because the handle might point to the first edge in the node, which has no
808817
/// pair to its left.
@@ -864,7 +873,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, handle::KV, NodeType
864873
}
865874
}
866875

867-
impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
876+
impl<'a, K: 'a, V: 'a, NodeRef: Deref<Target=Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
868877
NodeType> {
869878
// These are fine to include, but are currently unneeded.
870879
//
@@ -883,8 +892,9 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef
883892
// }
884893
}
885894

886-
impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
887-
NodeType> {
895+
impl<'a, K: 'a, V: 'a, NodeRef, NodeType> Handle<NodeRef, handle::KV, NodeType> where
896+
NodeRef: 'a + Deref<Target=Node<K, V>> + DerefMut,
897+
{
888898
/// Returns a mutable reference to the key pointed-to by this handle. This doesn't return a
889899
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
890900
/// handle.
@@ -900,7 +910,9 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<Node
900910
}
901911
}
902912

903-
impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, handle::KV, NodeType> {
913+
impl<K, V, NodeRef, NodeType> Handle<NodeRef, handle::KV, NodeType> where
914+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
915+
{
904916
/// Gets the handle pointing to the edge immediately to the left of the key/value pair pointed
905917
/// to by this handle.
906918
pub fn left_edge<'a>(&'a mut self) -> Handle<&'a mut Node<K, V>, handle::Edge, NodeType> {
@@ -920,7 +932,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>, NodeType> Handle<NodeRef, handle::KV,
920932
}
921933
}
922934

923-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Leaf> {
935+
impl<K, V, NodeRef> Handle<NodeRef, handle::KV, handle::Leaf> where
936+
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
937+
{
924938
/// Removes the key/value pair at the handle's location.
925939
///
926940
/// # Panics (in debug build)
@@ -931,7 +945,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Le
931945
}
932946
}
933947

934-
impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Internal> {
948+
impl<K, V, NodeRef> Handle<NodeRef, handle::KV, handle::Internal> where
949+
NodeRef: Deref<Target=Node<K, V>> + DerefMut
950+
{
935951
/// Steal! Stealing is roughly analogous to a binary tree rotation.
936952
/// In this case, we're "rotating" right.
937953
unsafe fn steal_rightward(&mut self) {

src/libcollections/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![feature(unsafe_destructor, slicing_syntax)]
2727
#![feature(unboxed_closures)]
2828
#![feature(old_orphan_check)]
29+
#![feature(associated_types)]
2930
#![no_std]
3031

3132
#[phase(plugin, link)] extern crate core;
@@ -121,7 +122,6 @@ mod prelude {
121122
pub use core::result::Result::{Ok, Err};
122123

123124
// in core and collections (may differ).
124-
pub use slice::{PartialEqSliceExt, OrdSliceExt};
125125
pub use slice::{AsSlice, SliceExt};
126126
pub use str::{from_str, Str, StrExt};
127127

@@ -130,7 +130,7 @@ mod prelude {
130130
pub use unicode::char::UnicodeChar;
131131

132132
// from collections.
133-
pub use slice::{CloneSliceExt, SliceConcatExt};
133+
pub use slice::SliceConcatExt;
134134
pub use str::IntoMaybeOwned;
135135
pub use string::{String, ToString};
136136
pub use vec::Vec;

0 commit comments

Comments
 (0)