diff --git a/src/librustc_data_structures/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs index c4c0db58012..7975c62b90f 100644 --- a/src/librustc_data_structures/fingerprint.rs +++ b/src/librustc_data_structures/fingerprint.rs @@ -39,8 +39,8 @@ impl Fingerprint { // you want. #[inline] pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint { - let a = (self.1 as u128) << 64 | self.0 as u128; - let b = (other.1 as u128) << 64 | other.0 as u128; + let a = u128::from(self.1) << 64 | u128::from(self.0); + let b = u128::from(other.1) << 64 | u128::from(other.0); let c = a.wrapping_add(b); diff --git a/src/librustc_data_structures/sip128.rs b/src/librustc_data_structures/sip128.rs index 06f157f9729..7838a900890 100644 --- a/src/librustc_data_structures/sip128.rs +++ b/src/librustc_data_structures/sip128.rs @@ -70,15 +70,15 @@ unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 { let mut i = 0; // current byte index (from LSB) in the output u64 let mut out = 0; if i + 3 < len { - out = load_int_le!(buf, start + i, u32) as u64; + out = u64::from(load_int_le!(buf, start + i, u32)); i += 4; } if i + 1 < len { - out |= (load_int_le!(buf, start + i, u16) as u64) << (i * 8); + out |= u64::from(load_int_le!(buf, start + i, u16)) << (i * 8); i += 2 } if i < len { - out |= (*buf.get_unchecked(start + i) as u64) << (i * 8); + out |= u64::from(*buf.get_unchecked(start + i)) << (i * 8); i += 1; } debug_assert_eq!(i, len); diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index 0c81c27a96e..47dfc1d1688 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -44,7 +44,7 @@ impl StableHasher { impl StableHasherResult for u128 { fn finish(hasher: StableHasher) -> Self { let (_0, _1) = hasher.finalize(); - (_0 as u128) | ((_1 as u128) << 64) + u128::from(_0) | (u128::from(_1) << 64) } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 826954ce216..a7e7c09f9ae 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -513,7 +513,7 @@ impl<'a> crate::Encoder for Encoder<'a> { emit_enquoted_if_mapkey!(self, fmt_number_or_null(v)) } fn emit_f32(&mut self, v: f32) -> EncodeResult { - self.emit_f64(v as f64) + self.emit_f64(f64::from(v)) } fn emit_char(&mut self, v: char) -> EncodeResult { @@ -763,7 +763,7 @@ impl<'a> crate::Encoder for PrettyEncoder<'a> { emit_enquoted_if_mapkey!(self, fmt_number_or_null(v)) } fn emit_f32(&mut self, v: f32) -> EncodeResult { - self.emit_f64(v as f64) + self.emit_f64(f64::from(v)) } fn emit_char(&mut self, v: char) -> EncodeResult { @@ -1698,12 +1698,12 @@ impl> Parser { if n2 < 0xDC00 || n2 > 0xDFFF { return self.error(LoneLeadingSurrogateInHexEscape) } - let c = (((n1 - 0xD800) as u32) << 10 | - (n2 - 0xDC00) as u32) + 0x1_0000; + let c = (u32::from(n1 - 0xD800) << 10 | + u32::from(n2 - 0xDC00)) + 0x1_0000; res.push(char::from_u32(c).unwrap()); } - n => match char::from_u32(n as u32) { + n => match char::from_u32(u32::from(n)) { Some(c) => res.push(c), None => return self.error(InvalidUnicodeCodePoint), }, @@ -2405,7 +2405,7 @@ impl ToJson for Json { } impl ToJson for f32 { - fn to_json(&self) -> Json { (*self as f64).to_json() } + fn to_json(&self) -> Json { f64::from(*self).to_json() } } impl ToJson for f64 { diff --git a/src/libserialize/leb128.rs b/src/libserialize/leb128.rs index 16ff59489e7..f9d80842d75 100644 --- a/src/libserialize/leb128.rs +++ b/src/libserialize/leb128.rs @@ -123,7 +123,7 @@ pub fn read_signed_leb128(data: &[u8], start_position: usize) -> (i128, usize) { loop { byte = data[position]; position += 1; - result |= ((byte & 0x7F) as i128) << shift; + result |= i128::from(byte & 0x7F) << shift; shift += 7; if (byte & 0x80) == 0 {