diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-05-20 20:57:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-20 20:57:28 +0200 |
| commit | c052d263d067094401852134d372a64adb695e43 (patch) | |
| tree | cb350b7b2867ec3bd6dec481f12138daec42cc36 | |
| parent | 7412a7c833c161e38205d4b4e3dbf7d47c106692 (diff) | |
| parent | 7b5ea0e7f5bece3ddde9a5891c853322cfc6c0f8 (diff) | |
| download | rust-c052d263d067094401852134d372a64adb695e43.tar.gz rust-c052d263d067094401852134d372a64adb695e43.zip | |
Rollup merge of #141289 - compiler-errors:more-self, r=jhpratt
use `Self` alias in self types rather than manually substituting it Of the rougly 145 uses of `self: Ty` in the standard library, 5 of them don't use `Self` but instead choose to manually "substitute" the `impl`'s self type into the type. This leads to weird behavior sometimes (https://github.com/rust-lang/rust/issues/140611#issuecomment-2883761300) -- **to be clear**, none of these usages actually trigger any bugs, but it's possible that they may break in the future (or at least lead to lints), so let's just "fix" them proactively.
| -rw-r--r-- | library/alloc/src/str.rs | 4 | ||||
| -rw-r--r-- | library/core/src/pin.rs | 2 | ||||
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 2 | ||||
| -rw-r--r-- | library/std/src/path.rs | 2 |
4 files changed, 5 insertions, 5 deletions
diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 24c5d4c92f7..8766fd904b0 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -234,7 +234,7 @@ impl str { #[stable(feature = "str_box_extras", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline] - pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> { + pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]> { self.into() } @@ -501,7 +501,7 @@ impl str { #[rustc_allow_incoherent_impl] #[must_use = "`self` will be dropped if the result is not used"] #[inline] - pub fn into_string(self: Box<str>) -> String { + pub fn into_string(self: Box<Self>) -> String { let slice = Box::<[u8]>::from(self); unsafe { String::from_utf8_unchecked(slice.into_vec()) } } diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 257424b355f..aad073cc8cd 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1419,7 +1419,7 @@ impl<Ptr: DerefMut> Pin<Ptr> { #[stable(feature = "pin_deref_mut", since = "1.84.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline(always)] - pub fn as_deref_mut(self: Pin<&mut Pin<Ptr>>) -> Pin<&mut Ptr::Target> { + pub fn as_deref_mut(self: Pin<&mut Self>) -> Pin<&mut Ptr::Target> { // SAFETY: What we're asserting here is that going from // // Pin<&mut Pin<Ptr>> diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 72bdf03ee61..ead48775127 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1040,7 +1040,7 @@ impl OsStr { /// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or allocating. #[stable(feature = "into_boxed_os_str", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] - pub fn into_os_string(self: Box<OsStr>) -> OsString { + pub fn into_os_string(self: Box<Self>) -> OsString { let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) }; OsString { inner: Buf::from_box(boxed) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 1a4a7aa7448..7959c633858 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3163,7 +3163,7 @@ impl Path { /// allocating. #[stable(feature = "into_boxed_path", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] - pub fn into_path_buf(self: Box<Path>) -> PathBuf { + pub fn into_path_buf(self: Box<Self>) -> PathBuf { let rw = Box::into_raw(self) as *mut OsStr; let inner = unsafe { Box::from_raw(rw) }; PathBuf { inner: OsString::from(inner) } |
