Skip to content
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

Make AsRef and AsMut reflexive #39397

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,20 +1818,6 @@ impl<T: fmt::Debug> fmt::Debug for Vec<T> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> AsRef<Vec<T>> for Vec<T> {
fn as_ref(&self) -> &Vec<T> {
self
}
}

#[stable(feature = "vec_as_mut", since = "1.5.0")]
impl<T> AsMut<Vec<T>> for Vec<T> {
fn as_mut(&mut self) -> &mut Vec<T> {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> AsRef<[T]> for Vec<T> {
fn as_ref(&self) -> &[T] {
Expand Down
42 changes: 16 additions & 26 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ pub trait TryFrom<T>: Sized {
// GENERIC IMPLS
////////////////////////////////////////////////////////////////////////////////

// As is reflexive
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> AsRef<T> for T {
fn as_ref(&self) -> &T {
self
}
}

// As lifts over &
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U> {
Expand All @@ -248,6 +256,14 @@ impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a mut T where T: AsRef<U> {
// }
// }

// AsMut is reflexive
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized> AsMut<T> for T {
fn as_mut(&mut self) -> &mut T {
self
}
}

// AsMut lifts over &mut
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
Expand Down Expand Up @@ -288,29 +304,3 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T> {
U::try_from(self)
}
}

////////////////////////////////////////////////////////////////////////////////
// CONCRETE IMPLS
////////////////////////////////////////////////////////////////////////////////

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> AsRef<[T]> for [T] {
fn as_ref(&self) -> &[T] {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> AsMut<[T]> for [T] {
fn as_mut(&mut self) -> &mut [T] {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<str> for str {
#[inline]
fn as_ref(&self) -> &str {
self
}
}
7 changes: 0 additions & 7 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,6 @@ impl ops::Index<ops::RangeFull> for CString {
}
}

#[stable(feature = "cstring_asref", since = "1.7.0")]
impl AsRef<CStr> for CStr {
fn as_ref(&self) -> &CStr {
self
}
}

#[stable(feature = "cstring_asref", since = "1.7.0")]
impl AsRef<CStr> for CString {
fn as_ref(&self) -> &CStr {
Expand Down
7 changes: 0 additions & 7 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,6 @@ impl ToOwned for OsStr {
fn to_owned(&self) -> OsString { self.to_os_string() }
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for OsStr {
fn as_ref(&self) -> &OsStr {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for OsString {
fn as_ref(&self) -> &OsStr {
Expand Down
7 changes: 0 additions & 7 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,13 +2129,6 @@ impl cmp::Ord for Path {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for Path {
fn as_ref(&self) -> &Path {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for OsStr {
fn as_ref(&self) -> &Path {
Expand Down