Skip to content

Commit c052d26

Browse files
authored
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 (#140611 (comment)) -- **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.
2 parents 7412a7c + 7b5ea0e commit c052d26

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

library/alloc/src/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl str {
234234
#[stable(feature = "str_box_extras", since = "1.20.0")]
235235
#[must_use = "`self` will be dropped if the result is not used"]
236236
#[inline]
237-
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
237+
pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]> {
238238
self.into()
239239
}
240240

@@ -501,7 +501,7 @@ impl str {
501501
#[rustc_allow_incoherent_impl]
502502
#[must_use = "`self` will be dropped if the result is not used"]
503503
#[inline]
504-
pub fn into_string(self: Box<str>) -> String {
504+
pub fn into_string(self: Box<Self>) -> String {
505505
let slice = Box::<[u8]>::from(self);
506506
unsafe { String::from_utf8_unchecked(slice.into_vec()) }
507507
}

library/core/src/pin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
14191419
#[stable(feature = "pin_deref_mut", since = "1.84.0")]
14201420
#[must_use = "`self` will be dropped if the result is not used"]
14211421
#[inline(always)]
1422-
pub fn as_deref_mut(self: Pin<&mut Pin<Ptr>>) -> Pin<&mut Ptr::Target> {
1422+
pub fn as_deref_mut(self: Pin<&mut Self>) -> Pin<&mut Ptr::Target> {
14231423
// SAFETY: What we're asserting here is that going from
14241424
//
14251425
// Pin<&mut Pin<Ptr>>

library/std/src/ffi/os_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ impl OsStr {
10401040
/// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or allocating.
10411041
#[stable(feature = "into_boxed_os_str", since = "1.20.0")]
10421042
#[must_use = "`self` will be dropped if the result is not used"]
1043-
pub fn into_os_string(self: Box<OsStr>) -> OsString {
1043+
pub fn into_os_string(self: Box<Self>) -> OsString {
10441044
let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) };
10451045
OsString { inner: Buf::from_box(boxed) }
10461046
}

library/std/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,7 @@ impl Path {
31633163
/// allocating.
31643164
#[stable(feature = "into_boxed_path", since = "1.20.0")]
31653165
#[must_use = "`self` will be dropped if the result is not used"]
3166-
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
3166+
pub fn into_path_buf(self: Box<Self>) -> PathBuf {
31673167
let rw = Box::into_raw(self) as *mut OsStr;
31683168
let inner = unsafe { Box::from_raw(rw) };
31693169
PathBuf { inner: OsString::from(inner) }

0 commit comments

Comments
 (0)