Skip to content

Commit

Permalink
rollup merge of #20410: japaric/assoc-types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcrichton committed Jan 2, 2015
2 parents 8cf9929 + 1abee08 commit 340f3fd
Show file tree
Hide file tree
Showing 74 changed files with 898 additions and 588 deletions.
4 changes: 3 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ impl<T> BorrowFrom<Arc<T>> for T {
}

#[experimental = "Deref is experimental."]
impl<T> Deref<T> for Arc<T> {
impl<T> Deref for Arc<T> {
type Target = T;

#[inline]
fn deref(&self) -> &T {
&self.inner().data
Expand Down
8 changes: 5 additions & 3 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ impl fmt::Show for Box<Any> {
}
}

impl<Sized? T> Deref<T> for Box<T> {
impl<Sized? T> Deref for Box<T> {
type Target = T;

fn deref(&self) -> &T { &**self }
}

impl<Sized? T> DerefMut<T> for Box<T> {
impl<Sized? T> DerefMut for Box<T> {
fn deref_mut(&mut self) -> &mut T { &mut **self }
}

Expand Down Expand Up @@ -212,7 +214,7 @@ mod test {

#[test]
fn deref() {
fn homura<T: Deref<i32>>(_: T) { }
fn homura<T: Deref<Target=i32>>(_: T) { }
homura(box 765i32);
}
}
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#![no_std]
#![allow(unknown_features)]
#![feature(lang_items, phase, unsafe_destructor, default_type_params, old_orphan_check)]
#![feature(associated_types)]

#[phase(plugin, link)]
extern crate core;
Expand Down
4 changes: 3 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ impl<T> BorrowFrom<Rc<T>> for T {
}

#[experimental = "Deref is experimental."]
impl<T> Deref<T> for Rc<T> {
impl<T> Deref for Rc<T> {
type Target = T;

#[inline(always)]
fn deref(&self) -> &T {
&self.inner().value
Expand Down
6 changes: 4 additions & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,15 @@ mod stack {
marker: marker::InvariantLifetime<'id>
}

impl<'id, T> Deref<T> for IdRef<'id, T> {
impl<'id, T> Deref for IdRef<'id, T> {
type Target = T;

fn deref(&self) -> &T {
&*self.inner
}
}

impl<'id, T> DerefMut<T> for IdRef<'id, T> {
impl<'id, T> DerefMut for IdRef<'id, T> {
fn deref_mut(&mut self) -> &mut T {
&mut *self.inner
}
Expand Down
48 changes: 32 additions & 16 deletions src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ impl<K: Clone, V: Clone> Clone for Node<K, V> {
/// flag: &'a Cell<bool>,
/// }
///
/// impl<'a> Deref<Node<uint, uint>> for Nasty<'a> {
/// impl<'a> Deref for Nasty<'a> {
/// type Target = Node<uint, uint>;
///
/// fn deref(&self) -> &Node<uint, uint> {
/// if self.flag.get() {
/// &*self.second
Expand Down Expand Up @@ -513,7 +515,7 @@ impl<K: Ord, V> Node<K, V> {
/// Searches for the given key in the node. If it finds an exact match,
/// `Found` will be yielded with the matching index. If it doesn't find an exact match,
/// `GoDown` will be yielded with the index of the subtree the key must lie in.
pub fn search<Sized? Q, NodeRef: Deref<Node<K, V>>>(node: NodeRef, key: &Q)
pub fn search<Sized? Q, NodeRef: Deref<Target=Node<K, V>>>(node: NodeRef, key: &Q)
-> SearchResult<NodeRef> where Q: BorrowFrom<K> + Ord {
// FIXME(Gankro): Tune when to search linear or binary based on B (and maybe K/V).
// For the B configured as of this writing (B = 6), binary search was *significantly*
Expand Down Expand Up @@ -590,7 +592,7 @@ impl <K, V> Node<K, V> {
}
}

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

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

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

impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafOrInternal> {
impl<K, V, NodeRef: Deref<Target=Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafOrInternal> {
/// Figure out whether this handle is pointing to something in a leaf node or to something in
/// an internal node, clarifying the type according to the result.
pub fn force(self) -> ForceResult<NodeRef, Type> {
Expand All @@ -686,8 +690,9 @@ impl<K, V, NodeRef: Deref<Node<K, V>>, Type> Handle<NodeRef, Type, handle::LeafO
}
}
}

impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::Leaf> {
impl<K, V, NodeRef> Handle<NodeRef, handle::Edge, handle::Leaf> where
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
{
/// Tries to insert this key-value pair at the given index in this leaf node
/// If the node is full, we have to split it.
///
Expand Down Expand Up @@ -719,7 +724,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::
}
}

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

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

impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
impl<'a, K: 'a, V: 'a, NodeRef: Deref<Target=Node<K, V>> + 'a, NodeType> Handle<NodeRef, handle::KV,
NodeType> {
// These are fine to include, but are currently unneeded.
//
Expand All @@ -883,8 +892,9 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef
// }
}

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

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

impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Leaf> {
impl<K, V, NodeRef> Handle<NodeRef, handle::KV, handle::Leaf> where
NodeRef: Deref<Target=Node<K, V>> + DerefMut,
{
/// Removes the key/value pair at the handle's location.
///
/// # Panics (in debug build)
Expand All @@ -931,7 +945,9 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Le
}
}

impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::KV, handle::Internal> {
impl<K, V, NodeRef> Handle<NodeRef, handle::KV, handle::Internal> where
NodeRef: Deref<Target=Node<K, V>> + DerefMut
{
/// Steal! Stealing is roughly analogous to a binary tree rotation.
/// In this case, we're "rotating" right.
unsafe fn steal_rightward(&mut self) {
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(unboxed_closures)]
#![feature(old_orphan_check)]
#![feature(associated_types)]
#![no_std]

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

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

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

// from collections.
pub use slice::{CloneSliceExt, SliceConcatExt};
pub use slice::SliceConcatExt;
pub use str::IntoMaybeOwned;
pub use string::{String, ToString};
pub use vec::Vec;
Expand Down

7 comments on commit 340f3fd

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at alexcrichton@340f3fd

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/rollup = 340f3fd into auto

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "c89417130f042c58adc60012e7cddc4ef70b70b9"}

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/rollup = 340f3fd merged ok, testing candidate = c894171

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c894171

@bors
Copy link
Contributor

@bors bors commented on 340f3fd Jan 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c894171

Please sign in to comment.