Skip to content

Commit 34716a3

Browse files
authored
Rollup merge of #67915 - lzutao:Self, r=Centril
Use Self instead of $type r? @Dylan-DPC
2 parents 162154f + c7dbf5a commit 34716a3

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

src/libcore/convert/num.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ macro_rules! impl_from {
4747
#[doc = $doc]
4848
impl From<$Small> for $Large {
4949
#[inline]
50-
fn from(small: $Small) -> $Large {
51-
small as $Large
50+
fn from(small: $Small) -> Self {
51+
small as Self
5252
}
5353
}
5454
};
@@ -177,7 +177,7 @@ macro_rules! try_from_unbounded {
177177
/// is outside of the range of the target type.
178178
#[inline]
179179
fn try_from(value: $source) -> Result<Self, Self::Error> {
180-
Ok(value as $target)
180+
Ok(value as Self)
181181
}
182182
}
183183
)*}
@@ -194,9 +194,9 @@ macro_rules! try_from_lower_bounded {
194194
/// number type. This returns an error if the source value
195195
/// is outside of the range of the target type.
196196
#[inline]
197-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
197+
fn try_from(u: $source) -> Result<Self, Self::Error> {
198198
if u >= 0 {
199-
Ok(u as $target)
199+
Ok(u as Self)
200200
} else {
201201
Err(TryFromIntError(()))
202202
}
@@ -216,11 +216,11 @@ macro_rules! try_from_upper_bounded {
216216
/// number type. This returns an error if the source value
217217
/// is outside of the range of the target type.
218218
#[inline]
219-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
220-
if u > (<$target>::max_value() as $source) {
219+
fn try_from(u: $source) -> Result<Self, Self::Error> {
220+
if u > (Self::max_value() as $source) {
221221
Err(TryFromIntError(()))
222222
} else {
223-
Ok(u as $target)
223+
Ok(u as Self)
224224
}
225225
}
226226
}
@@ -238,13 +238,13 @@ macro_rules! try_from_both_bounded {
238238
/// number type. This returns an error if the source value
239239
/// is outside of the range of the target type.
240240
#[inline]
241-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
242-
let min = <$target>::min_value() as $source;
243-
let max = <$target>::max_value() as $source;
241+
fn try_from(u: $source) -> Result<Self, Self::Error> {
242+
let min = Self::min_value() as $source;
243+
let max = Self::max_value() as $source;
244244
if u < min || u > max {
245245
Err(TryFromIntError(()))
246246
} else {
247-
Ok(u as $target)
247+
Ok(u as Self)
248248
}
249249
}
250250
}
@@ -385,10 +385,10 @@ macro_rules! nzint_impl_from {
385385
#[doc = $doc]
386386
impl From<$Small> for $Large {
387387
#[inline]
388-
fn from(small: $Small) -> $Large {
388+
fn from(small: $Small) -> Self {
389389
// SAFETY: input type guarantees the value is non-zero
390390
unsafe {
391-
<$Large>::new_unchecked(small.get().into())
391+
Self::new_unchecked(small.get().into())
392392
}
393393
}
394394
}

src/libcore/fmt/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ trait Int:
2424

2525
macro_rules! doit {
2626
($($t:ident)*) => ($(impl Int for $t {
27-
fn zero() -> $t { 0 }
28-
fn from_u8(u: u8) -> $t { u as $t }
27+
fn zero() -> Self { 0 }
28+
fn from_u8(u: u8) -> Self { u as Self }
2929
fn to_u8(&self) -> u8 { *self as u8 }
3030
fn to_u16(&self) -> u16 { *self as u16 }
3131
fn to_u32(&self) -> u32 { *self as u32 }

src/libcore/iter/traits/accum.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ macro_rules! integer_sum_product {
4444
(@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty)*) => ($(
4545
#[$attr]
4646
impl Sum for $a {
47-
fn sum<I: Iterator<Item=$a>>(iter: I) -> $a {
47+
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
4848
iter.fold($zero, Add::add)
4949
}
5050
}
5151

5252
#[$attr]
5353
impl Product for $a {
54-
fn product<I: Iterator<Item=$a>>(iter: I) -> $a {
54+
fn product<I: Iterator<Item=Self>>(iter: I) -> Self {
5555
iter.fold($one, Mul::mul)
5656
}
5757
}
5858

5959
#[$attr]
6060
impl<'a> Sum<&'a $a> for $a {
61-
fn sum<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
61+
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
6262
iter.fold($zero, Add::add)
6363
}
6464
}
6565

6666
#[$attr]
6767
impl<'a> Product<&'a $a> for $a {
68-
fn product<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
68+
fn product<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
6969
iter.fold($one, Mul::mul)
7070
}
7171
}
@@ -84,28 +84,28 @@ macro_rules! float_sum_product {
8484
($($a:ident)*) => ($(
8585
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
8686
impl Sum for $a {
87-
fn sum<I: Iterator<Item=$a>>(iter: I) -> $a {
87+
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
8888
iter.fold(0.0, Add::add)
8989
}
9090
}
9191

9292
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
9393
impl Product for $a {
94-
fn product<I: Iterator<Item=$a>>(iter: I) -> $a {
94+
fn product<I: Iterator<Item=Self>>(iter: I) -> Self {
9595
iter.fold(1.0, Mul::mul)
9696
}
9797
}
9898

9999
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
100100
impl<'a> Sum<&'a $a> for $a {
101-
fn sum<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
101+
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
102102
iter.fold(0.0, Add::add)
103103
}
104104
}
105105

106106
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
107107
impl<'a> Product<&'a $a> for $a {
108-
fn product<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
108+
fn product<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
109109
iter.fold(1.0, Mul::mul)
110110
}
111111
}

src/libcore/marker.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,15 @@ macro_rules! impls {
505505

506506
#[stable(feature = "rust1", since = "1.0.0")]
507507
impl<T: ?Sized> Clone for $t<T> {
508-
fn clone(&self) -> $t<T> {
509-
$t
508+
fn clone(&self) -> Self {
509+
Self
510510
}
511511
}
512512

513513
#[stable(feature = "rust1", since = "1.0.0")]
514514
impl<T: ?Sized> Default for $t<T> {
515-
fn default() -> $t<T> {
516-
$t
515+
fn default() -> Self {
516+
Self
517517
}
518518
}
519519

src/libcore/num/bignum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ macro_rules! define_bignum {
455455
}
456456

457457
impl crate::clone::Clone for $name {
458-
fn clone(&self) -> $name {
459-
$name { size: self.size, base: self.base }
458+
fn clone(&self) -> Self {
459+
Self { size: self.size, base: self.base }
460460
}
461461
}
462462

src/test/ui/issues/issue-8460.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ trait Int {
1111
}
1212
macro_rules! doit {
1313
($($t:ident)*) => ($(impl Int for $t {
14-
fn zero() -> $t { 0 }
15-
fn one() -> $t { 1 }
14+
fn zero() -> Self { 0 }
15+
fn one() -> Self { 1 }
1616
})*)
1717
}
1818
doit! { i8 i16 i32 i64 isize }

0 commit comments

Comments
 (0)