Skip to content

Commit 4aa3e27

Browse files
authored
Rollup merge of #62131 - Xanewok:clip-some-nits, r=petrochenkov
libsyntax: Fix some Clippy warnings When I was working on it before a lot of these popped up in the RLS so I figured I'll send a small patch fixing only the (hopefully) uncontroversial ones. Others that could be also fixed included also [`clippy::print_with_newline`](https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline) and [`clippy::cast_lossless`](https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless). Should I add them as well? since most of it touches libsyntax... r? @petrochenkov
2 parents bc335d6 + ad62b42 commit 4aa3e27

File tree

21 files changed

+49
-49
lines changed

21 files changed

+49
-49
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/obligation_forest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<O: ForestObligation> ObligationForest<O> {
263263
done_cache: Default::default(),
264264
waiting_cache: Default::default(),
265265
scratch: Some(vec![]),
266-
obligation_tree_id_generator: (0..).map(|i| ObligationTreeId(i)),
266+
obligation_tree_id_generator: (0..).map(ObligationTreeId),
267267
error_cache: Default::default(),
268268
}
269269
}

src/librustc_data_structures/sip128.rs

Lines changed: 4 additions & 4 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);
@@ -237,7 +237,7 @@ impl Hasher for SipHasher128 {
237237

238238
if self.ntail != 0 {
239239
needed = 8 - self.ntail;
240-
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail;
240+
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail);
241241
if length < needed {
242242
self.ntail += length;
243243
return

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/librustc_data_structures/vec_linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ where
88
Ls: Links,
99
{
1010
VecLinkedListIterator {
11-
links: links,
11+
links,
1212
current: first,
1313
}
1414
}

src/librustc_errors/annotate_snippet_emitter_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a> DiagnosticConverter<'a> {
9494
annotation_type: Self::annotation_type_for_level(self.level),
9595
}),
9696
footer: vec![],
97-
slices: slices,
97+
slices,
9898
})
9999
} else {
100100
// FIXME(#59346): Is it ok to return None if there's no source_map?

src/librustc_errors/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl Diagnostic {
388388
}],
389389
msg: msg.to_owned(),
390390
style: SuggestionStyle::CompletelyHidden,
391-
applicability: applicability,
391+
applicability,
392392
});
393393
self
394394
}

src/librustc_errors/emitter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ impl EmitterWriter {
13391339
}
13401340

13411341
let mut dst = self.dst.writable();
1342-
match write!(dst, "\n") {
1342+
match writeln!(dst) {
13431343
Err(e) => panic!("failed to emit error: {}", e),
13441344
_ => {
13451345
match dst.flush() {
@@ -1598,7 +1598,7 @@ fn emit_to_destination(rendered_buffer: &[Vec<StyledString>],
15981598
dst.reset()?;
15991599
}
16001600
if !short_message && (!lvl.is_failure_note() || pos != rendered_buffer.len() - 1) {
1601-
write!(dst, "\n")?;
1601+
writeln!(dst)?;
16021602
}
16031603
}
16041604
dst.flush()?;

src/librustc_target/spec/fuchsia_base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn opts() -> TargetOptions {
1919
is_like_fuchsia: true,
2020
linker_is_gnu: true,
2121
has_rpath: false,
22-
pre_link_args: pre_link_args,
22+
pre_link_args,
2323
pre_link_objects_exe: vec![
2424
"Scrt1.o".to_string()
2525
],

src/libserialize/json.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl<'a> Encoder<'a> {
461461
/// Creates a new JSON encoder whose output will be written to the writer
462462
/// specified.
463463
pub fn new(writer: &'a mut dyn fmt::Write) -> Encoder<'a> {
464-
Encoder { writer: writer, is_emitting_map_key: false, }
464+
Encoder { writer, is_emitting_map_key: false, }
465465
}
466466
}
467467

@@ -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 {

0 commit comments

Comments
 (0)