Skip to content

Associated types rollup #20410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 2, 2015
Merged
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 @@ -153,11 +153,13 @@ impl fmt::Show for Box<Any+'static> {
}
}

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 @@ -210,7 +212,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 @@ -65,6 +65,7 @@

#![no_std]
#![feature(lang_items, phase, unsafe_destructor, default_type_params)]
#![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 @@ -515,13 +515,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 @@ -455,7 +455,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 @@ -511,7 +513,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 @@ -588,7 +590,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 @@ -597,7 +599,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 @@ -653,7 +657,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 @@ -667,7 +671,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 @@ -684,8 +688,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 @@ -717,7 +722,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 @@ -800,7 +807,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 @@ -862,7 +871,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 @@ -881,8 +890,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 @@ -898,7 +908,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 @@ -918,7 +930,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 @@ -929,7 +943,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 @@ -25,6 +25,7 @@
#![feature(macro_rules, default_type_params, phase, globs)]
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(unboxed_closures)]
#![feature(associated_types)]
#![no_std]

#[phase(plugin, link)] extern crate core;
Expand Down Expand Up @@ -120,7 +121,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 @@ -129,7 +129,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
Loading