Skip to content

Commit 6c93b47

Browse files
committed
Fix clippy::cast_losless
1 parent 12806b7 commit 6c93b47

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/librustc_data_structures/fingerprint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl Fingerprint {
3939
// you want.
4040
#[inline]
4141
pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint {
42-
let a = (self.1 as u128) << 64 | self.0 as u128;
43-
let b = (other.1 as u128) << 64 | other.0 as u128;
42+
let a = u128::from(self.1) << 64 | u128::from(self.0);
43+
let b = u128::from(other.1) << 64 | u128::from(other.0);
4444

4545
let c = a.wrapping_add(b);
4646

src/librustc_data_structures/sip128.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
7070
let mut i = 0; // current byte index (from LSB) in the output u64
7171
let mut out = 0;
7272
if i + 3 < len {
73-
out = load_int_le!(buf, start + i, u32) as u64;
73+
out = u64::from(load_int_le!(buf, start + i, u32));
7474
i += 4;
7575
}
7676
if i + 1 < len {
77-
out |= (load_int_le!(buf, start + i, u16) as u64) << (i * 8);
77+
out |= u64::from(load_int_le!(buf, start + i, u16)) << (i * 8);
7878
i += 2
7979
}
8080
if i < len {
81-
out |= (*buf.get_unchecked(start + i) as u64) << (i * 8);
81+
out |= u64::from(*buf.get_unchecked(start + i)) << (i * 8);
8282
i += 1;
8383
}
8484
debug_assert_eq!(i, len);

src/librustc_data_structures/stable_hasher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<W: StableHasherResult> StableHasher<W> {
4444
impl StableHasherResult for u128 {
4545
fn finish(hasher: StableHasher<Self>) -> Self {
4646
let (_0, _1) = hasher.finalize();
47-
(_0 as u128) | ((_1 as u128) << 64)
47+
u128::from(_0) | (u128::from(_1) << 64)
4848
}
4949
}
5050

src/libserialize/json.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl<'a> crate::Encoder for Encoder<'a> {
513513
emit_enquoted_if_mapkey!(self, fmt_number_or_null(v))
514514
}
515515
fn emit_f32(&mut self, v: f32) -> EncodeResult {
516-
self.emit_f64(v as f64)
516+
self.emit_f64(f64::from(v))
517517
}
518518

519519
fn emit_char(&mut self, v: char) -> EncodeResult {
@@ -763,7 +763,7 @@ impl<'a> crate::Encoder for PrettyEncoder<'a> {
763763
emit_enquoted_if_mapkey!(self, fmt_number_or_null(v))
764764
}
765765
fn emit_f32(&mut self, v: f32) -> EncodeResult {
766-
self.emit_f64(v as f64)
766+
self.emit_f64(f64::from(v))
767767
}
768768

769769
fn emit_char(&mut self, v: char) -> EncodeResult {
@@ -1698,12 +1698,12 @@ impl<T: Iterator<Item=char>> Parser<T> {
16981698
if n2 < 0xDC00 || n2 > 0xDFFF {
16991699
return self.error(LoneLeadingSurrogateInHexEscape)
17001700
}
1701-
let c = (((n1 - 0xD800) as u32) << 10 |
1702-
(n2 - 0xDC00) as u32) + 0x1_0000;
1701+
let c = (u32::from(n1 - 0xD800) << 10 |
1702+
u32::from(n2 - 0xDC00)) + 0x1_0000;
17031703
res.push(char::from_u32(c).unwrap());
17041704
}
17051705

1706-
n => match char::from_u32(n as u32) {
1706+
n => match char::from_u32(u32::from(n)) {
17071707
Some(c) => res.push(c),
17081708
None => return self.error(InvalidUnicodeCodePoint),
17091709
},
@@ -2405,7 +2405,7 @@ impl ToJson for Json {
24052405
}
24062406

24072407
impl ToJson for f32 {
2408-
fn to_json(&self) -> Json { (*self as f64).to_json() }
2408+
fn to_json(&self) -> Json { f64::from(*self).to_json() }
24092409
}
24102410

24112411
impl ToJson for f64 {

src/libserialize/leb128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn read_signed_leb128(data: &[u8], start_position: usize) -> (i128, usize) {
123123
loop {
124124
byte = data[position];
125125
position += 1;
126-
result |= ((byte & 0x7F) as i128) << shift;
126+
result |= i128::from(byte & 0x7F) << shift;
127127
shift += 7;
128128

129129
if (byte & 0x80) == 0 {

0 commit comments

Comments
 (0)