Skip to content

Commit 4a9884d

Browse files
author
Clar Charr
committed
Make AsRef and AsMut reflexive (BREAKING).
1 parent 4be49e1 commit 4a9884d

File tree

5 files changed

+16
-61
lines changed

5 files changed

+16
-61
lines changed

src/libcollections/vec.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,20 +1818,6 @@ impl<T: fmt::Debug> fmt::Debug for Vec<T> {
18181818
}
18191819
}
18201820

1821-
#[stable(feature = "rust1", since = "1.0.0")]
1822-
impl<T> AsRef<Vec<T>> for Vec<T> {
1823-
fn as_ref(&self) -> &Vec<T> {
1824-
self
1825-
}
1826-
}
1827-
1828-
#[stable(feature = "vec_as_mut", since = "1.5.0")]
1829-
impl<T> AsMut<Vec<T>> for Vec<T> {
1830-
fn as_mut(&mut self) -> &mut Vec<T> {
1831-
self
1832-
}
1833-
}
1834-
18351821
#[stable(feature = "rust1", since = "1.0.0")]
18361822
impl<T> AsRef<[T]> for Vec<T> {
18371823
fn as_ref(&self) -> &[T] {

src/libcore/convert.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ pub trait TryFrom<T>: Sized {
224224
// GENERIC IMPLS
225225
////////////////////////////////////////////////////////////////////////////////
226226

227+
// As is reflexive
228+
#[stable(feature = "rust1", since = "1.0.0")]
229+
impl<'a, T: ?Sized> AsRef<T> for T {
230+
fn as_ref(&self) -> &T {
231+
self
232+
}
233+
}
234+
227235
// As lifts over &
228236
#[stable(feature = "rust1", since = "1.0.0")]
229237
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U> {
@@ -248,6 +256,14 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U> {
248256
// }
249257
// }
250258

259+
// AsMut is reflexive
260+
#[stable(feature = "rust1", since = "1.0.0")]
261+
impl<'a, T: ?Sized> AsMut<T> for T {
262+
fn as_mut(&mut self) -> &mut T {
263+
self
264+
}
265+
}
266+
251267
// AsMut lifts over &mut
252268
#[stable(feature = "rust1", since = "1.0.0")]
253269
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
@@ -288,29 +304,3 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T> {
288304
U::try_from(self)
289305
}
290306
}
291-
292-
////////////////////////////////////////////////////////////////////////////////
293-
// CONCRETE IMPLS
294-
////////////////////////////////////////////////////////////////////////////////
295-
296-
#[stable(feature = "rust1", since = "1.0.0")]
297-
impl<T> AsRef<[T]> for [T] {
298-
fn as_ref(&self) -> &[T] {
299-
self
300-
}
301-
}
302-
303-
#[stable(feature = "rust1", since = "1.0.0")]
304-
impl<T> AsMut<[T]> for [T] {
305-
fn as_mut(&mut self) -> &mut [T] {
306-
self
307-
}
308-
}
309-
310-
#[stable(feature = "rust1", since = "1.0.0")]
311-
impl AsRef<str> for str {
312-
#[inline]
313-
fn as_ref(&self) -> &str {
314-
self
315-
}
316-
}

src/libstd/ffi/c_str.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,6 @@ impl ops::Index<ops::RangeFull> for CString {
707707
}
708708
}
709709

710-
#[stable(feature = "cstring_asref", since = "1.7.0")]
711-
impl AsRef<CStr> for CStr {
712-
fn as_ref(&self) -> &CStr {
713-
self
714-
}
715-
}
716-
717710
#[stable(feature = "cstring_asref", since = "1.7.0")]
718711
impl AsRef<CStr> for CString {
719712
fn as_ref(&self) -> &CStr {

src/libstd/ffi/os_str.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,6 @@ impl ToOwned for OsStr {
575575
fn to_owned(&self) -> OsString { self.to_os_string() }
576576
}
577577

578-
#[stable(feature = "rust1", since = "1.0.0")]
579-
impl AsRef<OsStr> for OsStr {
580-
fn as_ref(&self) -> &OsStr {
581-
self
582-
}
583-
}
584-
585578
#[stable(feature = "rust1", since = "1.0.0")]
586579
impl AsRef<OsStr> for OsString {
587580
fn as_ref(&self) -> &OsStr {

src/libstd/path.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,13 +2129,6 @@ impl cmp::Ord for Path {
21292129
}
21302130
}
21312131

2132-
#[stable(feature = "rust1", since = "1.0.0")]
2133-
impl AsRef<Path> for Path {
2134-
fn as_ref(&self) -> &Path {
2135-
self
2136-
}
2137-
}
2138-
21392132
#[stable(feature = "rust1", since = "1.0.0")]
21402133
impl AsRef<Path> for OsStr {
21412134
fn as_ref(&self) -> &Path {

0 commit comments

Comments
 (0)