Change:
As titled. Add the following trait implementations: This allows generic code that accepts smart pointer can take references too, e.g.
cc
yes I want this :+1:
This would also allow code to be polymorphic over &T and &mut T by accepting . A huge win imho.
The branch creates some .

Discussion:
// additional reference of either kind. if self.inner().strong.load(atomic::SeqCst) != 1 || self.inner().weak.load(atomic::SeqCst) != 1 { <del> *self = Arc::new(self.deref().clone()) </del> <ins> *self = Arc::new((**self).clone()) </ins> } // This unsafety is ok because we're guaranteed that the pointer // returned is the *only* pointer that will ever be returned to T. Our

fn deref<'a>(&'a self) -> &'a Result; } <ins> #[cfg(not(stage0))] impl<'a, Sized? T> Deref<T> for &'a T { fn deref(&self) -> &T { *self } } #[cfg(not(stage0))] impl<'a, Sized? T> Deref<T> for &'a mut T { fn deref(&self) -> &T { *self } } </ins> /** * * The `DerefMut` trait is used to specify the functionality of dereferencing

fn deref_mut<'a>(&'a mut self) -> &'a mut Result; } <ins> #[cfg(not(stage0))] impl<'a, Sized? T> DerefMut<T> for &'a mut T { fn deref_mut(&mut self) -> &mut T { *self } } </ins> /// A version of the call operator that takes an immutable receiver. #[lang="fn"] pub trait Fn<Args,Result> {

PreferMutLvalue); } ast::ExprUnary(ast::UnDeref, ref base_expr) => { <del> check::try_overloaded_deref( self.fcx, expr.span, Some(MethodCall::expr(expr.id)), Some(&**base_expr), self.fcx.expr_ty(&**base_expr), PreferMutLvalue); </del> <ins> // if this is an overloaded deref, then re-evaluate with // a preference for mut let method_call = MethodCall::expr(expr.id); if self.fcx.inh.method_map.borrow().contains_key(&method_call) { check::try_overloaded_deref( self.fcx, expr.span, Some(method_call), Some(&**base_expr), self.fcx.expr_ty(&**base_expr), PreferMutLvalue); } </ins> } _ => {} }

} // For parameterizing over mutability. <ins> #[cfg(stage0)] </ins> impl<'t, K, V> Deref<RawTable<K, V>> for &'t RawTable<K, V> { fn deref(&self) -> &RawTable<K, V> { &**self } } <ins> #[cfg(stage0)] </ins> impl<'t, K, V> Deref<RawTable<K, V>> for &'t mut RawTable<K, V> { fn deref(&self) -> &RawTable<K,V> { &**self } } <ins> #[cfg(stage0)] </ins> impl<'t, K, V> DerefMut<RawTable<K, V>> for &'t mut RawTable<K, V> { fn deref_mut(&mut self) -> &mut RawTable<K,V> { &mut **self

<ins> // Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Test that `&mut T` implements `DerefMut<T>` fn inc<T:DerefMut<int>>(mut t: T) { *t += 1; } fn main() { let mut x: int = 5; inc(&mut x); assert_eq!(x, 6); } </ins>

<ins> // Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // Test that `&T` and `&mut T` implement `Deref<T>` fn deref<U:Copy,T:Deref<U>>(t: T) -> U { *t } fn main() { let x: int = 3; let y = deref(&x); assert_eq!(y, 3); let mut x: int = 4; let y = deref(&mut x); assert_eq!(y, 4); } </ins>