diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs index 596da6f786bbd..752199c94b8ae 100644 --- a/src/libcore/convert/num.rs +++ b/src/libcore/convert/num.rs @@ -47,8 +47,8 @@ macro_rules! impl_from { #[doc = $doc] impl From<$Small> for $Large { #[inline] - fn from(small: $Small) -> $Large { - small as $Large + fn from(small: $Small) -> Self { + small as Self } } }; @@ -177,7 +177,7 @@ macro_rules! try_from_unbounded { /// is outside of the range of the target type. #[inline] fn try_from(value: $source) -> Result { - Ok(value as $target) + Ok(value as Self) } } )*} @@ -194,9 +194,9 @@ macro_rules! try_from_lower_bounded { /// number type. This returns an error if the source value /// is outside of the range of the target type. #[inline] - fn try_from(u: $source) -> Result<$target, TryFromIntError> { + fn try_from(u: $source) -> Result { if u >= 0 { - Ok(u as $target) + Ok(u as Self) } else { Err(TryFromIntError(())) } @@ -216,11 +216,11 @@ macro_rules! try_from_upper_bounded { /// number type. This returns an error if the source value /// is outside of the range of the target type. #[inline] - fn try_from(u: $source) -> Result<$target, TryFromIntError> { - if u > (<$target>::max_value() as $source) { + fn try_from(u: $source) -> Result { + if u > (Self::max_value() as $source) { Err(TryFromIntError(())) } else { - Ok(u as $target) + Ok(u as Self) } } } @@ -238,13 +238,13 @@ macro_rules! try_from_both_bounded { /// number type. This returns an error if the source value /// is outside of the range of the target type. #[inline] - fn try_from(u: $source) -> Result<$target, TryFromIntError> { - let min = <$target>::min_value() as $source; - let max = <$target>::max_value() as $source; + fn try_from(u: $source) -> Result { + let min = Self::min_value() as $source; + let max = Self::max_value() as $source; if u < min || u > max { Err(TryFromIntError(())) } else { - Ok(u as $target) + Ok(u as Self) } } } @@ -385,10 +385,10 @@ macro_rules! nzint_impl_from { #[doc = $doc] impl From<$Small> for $Large { #[inline] - fn from(small: $Small) -> $Large { + fn from(small: $Small) -> Self { // SAFETY: input type guarantees the value is non-zero unsafe { - <$Large>::new_unchecked(small.get().into()) + Self::new_unchecked(small.get().into()) } } } diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 7b20677ffb54c..d562639a6588d 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -24,8 +24,8 @@ trait Int: macro_rules! doit { ($($t:ident)*) => ($(impl Int for $t { - fn zero() -> $t { 0 } - fn from_u8(u: u8) -> $t { u as $t } + fn zero() -> Self { 0 } + fn from_u8(u: u8) -> Self { u as Self } fn to_u8(&self) -> u8 { *self as u8 } fn to_u16(&self) -> u16 { *self as u16 } fn to_u32(&self) -> u32 { *self as u32 } diff --git a/src/libcore/iter/traits/accum.rs b/src/libcore/iter/traits/accum.rs index 65af671ddf204..55f30794af652 100644 --- a/src/libcore/iter/traits/accum.rs +++ b/src/libcore/iter/traits/accum.rs @@ -44,28 +44,28 @@ macro_rules! integer_sum_product { (@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty)*) => ($( #[$attr] impl Sum for $a { - fn sum>(iter: I) -> $a { + fn sum>(iter: I) -> Self { iter.fold($zero, Add::add) } } #[$attr] impl Product for $a { - fn product>(iter: I) -> $a { + fn product>(iter: I) -> Self { iter.fold($one, Mul::mul) } } #[$attr] impl<'a> Sum<&'a $a> for $a { - fn sum>(iter: I) -> $a { + fn sum>(iter: I) -> Self { iter.fold($zero, Add::add) } } #[$attr] impl<'a> Product<&'a $a> for $a { - fn product>(iter: I) -> $a { + fn product>(iter: I) -> Self { iter.fold($one, Mul::mul) } } @@ -84,28 +84,28 @@ macro_rules! float_sum_product { ($($a:ident)*) => ($( #[stable(feature = "iter_arith_traits", since = "1.12.0")] impl Sum for $a { - fn sum>(iter: I) -> $a { + fn sum>(iter: I) -> Self { iter.fold(0.0, Add::add) } } #[stable(feature = "iter_arith_traits", since = "1.12.0")] impl Product for $a { - fn product>(iter: I) -> $a { + fn product>(iter: I) -> Self { iter.fold(1.0, Mul::mul) } } #[stable(feature = "iter_arith_traits", since = "1.12.0")] impl<'a> Sum<&'a $a> for $a { - fn sum>(iter: I) -> $a { + fn sum>(iter: I) -> Self { iter.fold(0.0, Add::add) } } #[stable(feature = "iter_arith_traits", since = "1.12.0")] impl<'a> Product<&'a $a> for $a { - fn product>(iter: I) -> $a { + fn product>(iter: I) -> Self { iter.fold(1.0, Mul::mul) } } diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 3b98bc1c272f0..b4b595f330e22 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -505,15 +505,15 @@ macro_rules! impls { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for $t { - fn clone(&self) -> $t { - $t + fn clone(&self) -> Self { + Self } } #[stable(feature = "rust1", since = "1.0.0")] impl Default for $t { - fn default() -> $t { - $t + fn default() -> Self { + Self } } diff --git a/src/libcore/num/bignum.rs b/src/libcore/num/bignum.rs index 39cc381b64c74..6f16b93d0488a 100644 --- a/src/libcore/num/bignum.rs +++ b/src/libcore/num/bignum.rs @@ -455,8 +455,8 @@ macro_rules! define_bignum { } impl crate::clone::Clone for $name { - fn clone(&self) -> $name { - $name { size: self.size, base: self.base } + fn clone(&self) -> Self { + Self { size: self.size, base: self.base } } } diff --git a/src/test/ui/issues/issue-8460.rs b/src/test/ui/issues/issue-8460.rs index b7fc564a9b59a..3fd576a8d3580 100644 --- a/src/test/ui/issues/issue-8460.rs +++ b/src/test/ui/issues/issue-8460.rs @@ -11,8 +11,8 @@ trait Int { } macro_rules! doit { ($($t:ident)*) => ($(impl Int for $t { - fn zero() -> $t { 0 } - fn one() -> $t { 1 } + fn zero() -> Self { 0 } + fn one() -> Self { 1 } })*) } doit! { i8 i16 i32 i64 isize }