Skip to content

Commit 0d8c956

Browse files
authored
Rollup merge of rust-lang#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 4fade7a + ad62b42 commit 0d8c956

File tree

21 files changed

+49
-49
lines changed

21 files changed

+49
-49
lines changed

src/librustc_data_structures/fingerprint.rs

+2-2
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

+1-1
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

+4-4
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

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

src/libserialize/leb128.rs

+1-1
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 {

src/libserialize/opaque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ impl<'a> serialize::Decoder for Decoder<'a> {
296296
#[inline]
297297
fn read_f64(&mut self) -> Result<f64, Self::Error> {
298298
let bits = self.read_u64()?;
299-
Ok(unsafe { ::std::mem::transmute(bits) })
299+
Ok(f64::from_bits(bits))
300300
}
301301

302302
#[inline]
303303
fn read_f32(&mut self) -> Result<f32, Self::Error> {
304304
let bits = self.read_u32()?;
305-
Ok(unsafe { ::std::mem::transmute(bits) })
305+
Ok(f32::from_bits(bits))
306306
}
307307

308308
#[inline]

src/libsyntax/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ impl Arg {
18321832
lt,
18331833
MutTy {
18341834
ty: infer_ty,
1835-
mutbl: mutbl,
1835+
mutbl,
18361836
},
18371837
),
18381838
span,
@@ -2120,7 +2120,7 @@ impl PolyTraitRef {
21202120
PolyTraitRef {
21212121
bound_generic_params: generic_params,
21222122
trait_ref: TraitRef {
2123-
path: path,
2123+
path,
21242124
ref_id: DUMMY_NODE_ID,
21252125
},
21262126
span,

src/libsyntax/ext/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
815815

816816

817817
fn pat(&self, span: Span, pat: PatKind) -> P<ast::Pat> {
818-
P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span })
818+
P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span })
819819
}
820820
fn pat_wild(&self, span: Span) -> P<ast::Pat> {
821821
self.pat(span, PatKind::Wild)

src/libsyntax/ext/expand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub struct MacroExpander<'a, 'b> {
231231

232232
impl<'a, 'b> MacroExpander<'a, 'b> {
233233
pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
234-
MacroExpander { cx: cx, monotonic: monotonic }
234+
MacroExpander { cx, monotonic }
235235
}
236236

237237
pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
@@ -377,7 +377,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
377377
_ => item.clone(),
378378
};
379379
invocations.push(Invocation {
380-
kind: InvocationKind::Derive { path: path.clone(), item: item },
380+
kind: InvocationKind::Derive { path: path.clone(), item },
381381
fragment_kind: invoc.fragment_kind,
382382
expansion_data: ExpansionData {
383383
mark,
@@ -944,7 +944,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
944944
}
945945

946946
fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: AstFragmentKind) -> AstFragment {
947-
self.collect(kind, InvocationKind::Bang { mac: mac, ident: None, span: span })
947+
self.collect(kind, InvocationKind::Bang { mac, ident: None, span })
948948
}
949949

950950
fn collect_attr(&mut self,

src/libsyntax/ext/tt/quoted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn parse_tree(
319319
tokenstream::TokenTree::Delimited(span, delim, tts) => TokenTree::Delimited(
320320
span,
321321
Lrc::new(Delimited {
322-
delim: delim,
322+
delim,
323323
tts: parse(
324324
tts.into(),
325325
expect_matchers,

src/libsyntax/ext/tt/transcribe.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ enum Frame {
2323
impl Frame {
2424
/// Construct a new frame around the delimited set of tokens.
2525
fn new(tts: Vec<quoted::TokenTree>) -> Frame {
26-
let forest = Lrc::new(quoted::Delimited { delim: token::NoDelim, tts: tts });
27-
Frame::Delimited { forest: forest, idx: 0, span: DelimSpan::dummy() }
26+
let forest = Lrc::new(quoted::Delimited { delim: token::NoDelim, tts });
27+
Frame::Delimited { forest, idx: 0, span: DelimSpan::dummy() }
2828
}
2929
}
3030

@@ -248,7 +248,7 @@ pub fn transcribe(
248248
// the previous results (from outside the Delimited).
249249
quoted::TokenTree::Delimited(mut span, delimited) => {
250250
span = span.apply_mark(cx.current_expansion.mark);
251-
stack.push(Frame::Delimited { forest: delimited, idx: 0, span: span });
251+
stack.push(Frame::Delimited { forest: delimited, idx: 0, span });
252252
result_stack.push(mem::replace(&mut result, Vec::new()));
253253
}
254254

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ impl<'a> Context<'a> {
16651665
}
16661666

16671667
pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features: &Features) {
1668-
let cx = Context { features: features, parse_sess: parse_sess, plugin_attributes: &[] };
1668+
let cx = Context { features, parse_sess, plugin_attributes: &[] };
16691669
cx.check_attribute(
16701670
attr,
16711671
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name).map(|a| *a)),

src/libsyntax/parse/parser.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ crate enum LastToken {
290290
}
291291

292292
impl TokenCursorFrame {
293-
fn new(sp: DelimSpan, delim: DelimToken, tts: &TokenStream) -> Self {
293+
fn new(span: DelimSpan, delim: DelimToken, tts: &TokenStream) -> Self {
294294
TokenCursorFrame {
295-
delim: delim,
296-
span: sp,
295+
delim,
296+
span,
297297
open_delim: delim == token::NoDelim,
298298
tree_cursor: tts.clone().into_trees(),
299299
close_delim: delim == token::NoDelim,
@@ -1449,7 +1449,7 @@ impl<'a> Parser<'a> {
14491449
let opt_lifetime = if self.check_lifetime() { Some(self.expect_lifetime()) } else { None };
14501450
let mutbl = self.parse_mutability();
14511451
let ty = self.parse_ty_no_plus()?;
1452-
return Ok(TyKind::Rptr(opt_lifetime, MutTy { ty: ty, mutbl: mutbl }));
1452+
return Ok(TyKind::Rptr(opt_lifetime, MutTy { ty, mutbl }));
14531453
}
14541454

14551455
fn parse_ptr(&mut self) -> PResult<'a, MutTy> {
@@ -1467,7 +1467,7 @@ impl<'a> Parser<'a> {
14671467
Mutability::Immutable
14681468
};
14691469
let t = self.parse_ty_no_plus()?;
1470-
Ok(MutTy { ty: t, mutbl: mutbl })
1470+
Ok(MutTy { ty: t, mutbl })
14711471
}
14721472

14731473
fn is_named_argument(&self) -> bool {
@@ -4366,7 +4366,7 @@ impl<'a> Parser<'a> {
43664366
self.report_invalid_macro_expansion_item();
43674367
}
43684368

4369-
(ident, ast::MacroDef { tokens: tokens, legacy: true })
4369+
(ident, ast::MacroDef { tokens, legacy: true })
43704370
}
43714371
_ => return Ok(None),
43724372
};
@@ -6789,12 +6789,12 @@ impl<'a> Parser<'a> {
67896789
let hi = self.token.span;
67906790
self.expect(&token::Semi)?;
67916791
Ok(ast::ForeignItem {
6792-
ident: ident,
6793-
attrs: attrs,
6792+
ident,
6793+
attrs,
67946794
node: ForeignItemKind::Ty,
67956795
id: ast::DUMMY_NODE_ID,
67966796
span: lo.to(hi),
6797-
vis: vis
6797+
vis
67986798
})
67996799
}
68006800

src/libsyntax/print/pp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a> Printer<'a> {
497497

498498
pub fn print_newline(&mut self, amount: isize) -> io::Result<()> {
499499
debug!("NEWLINE {}", amount);
500-
let ret = write!(self.out, "\n");
500+
let ret = writeln!(self.out);
501501
self.pending_indentation = 0;
502502
self.indent(amount);
503503
ret

src/libsyntax/source_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl SourceMap {
150150
-> SourceMap {
151151
SourceMap {
152152
files: Default::default(),
153-
file_loader: file_loader,
153+
file_loader,
154154
path_mapping,
155155
}
156156
}
@@ -396,7 +396,7 @@ impl SourceMap {
396396
let f = (*self.files.borrow().source_files)[idx].clone();
397397

398398
match f.lookup_line(pos) {
399-
Some(line) => Ok(SourceFileAndLine { sf: f, line: line }),
399+
Some(line) => Ok(SourceFileAndLine { sf: f, line }),
400400
None => Err(f)
401401
}
402402
}
@@ -511,7 +511,7 @@ impl SourceMap {
511511
start_col,
512512
end_col: hi.col });
513513

514-
Ok(FileLines {file: lo.file, lines: lines})
514+
Ok(FileLines {file: lo.file, lines})
515515
}
516516

517517
/// Extracts the source surrounding the given `Span` using the `extract_source` function. The
@@ -820,7 +820,7 @@ impl SourceMap {
820820
let idx = self.lookup_source_file_idx(bpos);
821821
let sf = (*self.files.borrow().source_files)[idx].clone();
822822
let offset = bpos - sf.start_pos;
823-
SourceFileAndBytePos {sf: sf, pos: offset}
823+
SourceFileAndBytePos {sf, pos: offset}
824824
}
825825

826826
/// Converts an absolute BytePos to a CharPos relative to the source_file.

0 commit comments

Comments
 (0)