Skip to content

Commit 2ac1598

Browse files
authored
Rollup merge of #73172 - matthiaskrgr:cl9ppy, r=Dylan-DPC
Fix more clippy warnings Fixes more of: clippy::unused_unit clippy::op_ref clippy::useless_format clippy::needless_return clippy::useless_conversion clippy::bind_instead_of_map clippy::into_iter_on_ref clippy::redundant_clone clippy::nonminimal_bool clippy::redundant_closure clippy::option_as_ref_deref clippy::len_zero clippy::iter_cloned_collect clippy::filter_next r? @Dylan-DPC
2 parents 70c14c2 + 58023fe commit 2ac1598

File tree

18 files changed

+25
-34
lines changed

18 files changed

+25
-34
lines changed

src/librustc_ast/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl TokenStream {
392392
break;
393393
}
394394
}
395-
token_trees = out.into_iter().map(|t| TokenTree::Token(t)).collect();
395+
token_trees = out.into_iter().map(TokenTree::Token).collect();
396396
if token_trees.len() != 1 {
397397
debug!("break_tokens: broke {:?} to {:?}", tree, token_trees);
398398
}

src/librustc_ast_lowering/expr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1237,10 +1237,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
12371237
) => {
12381238
assert!(!*late);
12391239
let out_op_sp = if input { op_sp2 } else { op_sp };
1240-
let msg = &format!(
1241-
"use `lateout` instead of \
1242-
`out` to avoid conflict"
1243-
);
1240+
let msg = "use `lateout` instead of \
1241+
`out` to avoid conflict";
12441242
err.span_help(out_op_sp, msg);
12451243
}
12461244
_ => {}

src/librustc_builtin_macros/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
457457

458458
let mut chars = arg.format.ty.chars();
459459
let mut modifier = chars.next();
460-
if !chars.next().is_none() {
460+
if chars.next().is_some() {
461461
let span = arg
462462
.format
463463
.ty_span

src/librustc_codegen_ssa/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6363
.tcx()
6464
.destructure_const(ty::ParamEnv::reveal_all().and(&c))
6565
.fields
66-
.into_iter()
66+
.iter()
6767
.map(|field| {
6868
if let Some(prim) = field.val.try_to_scalar() {
6969
let layout = bx.layout_of(field_ty);

src/librustc_errors/annotate_snippet_emitter_writer.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,10 @@ impl AnnotateSnippetEmitterWriter {
159159
// FIXME(#59346): Not really sure when `fold` should be true or false
160160
fold: false,
161161
annotations: annotations
162-
.into_iter()
162+
.iter()
163163
.map(|annotation| SourceAnnotation {
164164
range: (annotation.start_col, annotation.end_col),
165-
label: annotation
166-
.label
167-
.as_ref()
168-
.map(|s| s.as_str())
169-
.unwrap_or_default(),
165+
label: annotation.label.as_deref().unwrap_or_default(),
170166
annotation_type: annotation_type_for_level(*level),
171167
})
172168
.collect(),

src/librustc_infer/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
550550
let error_code = error_code.into();
551551
let mut err = self.tcx.sess.struct_span_err_with_code(
552552
local_visitor.target_span,
553-
&format!("type annotations needed"),
553+
"type annotations needed",
554554
error_code,
555555
);
556556

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7777
}
7878
_ => {}
7979
}
80-
let mut type_param_span: MultiSpan =
81-
visitor.types.iter().cloned().collect::<Vec<_>>().into();
80+
let mut type_param_span: MultiSpan = visitor.types.to_vec().into();
8281
for &span in &visitor.types {
8382
type_param_span.push_span_label(
8483
span,

src/librustc_lexer/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
187187
// Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
188188
// a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
189189
// then it may be valid Rust code, so consider it Rust code.
190-
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).filter(|tok|
190+
let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok|
191191
!matches!(tok, TokenKind::Whitespace | TokenKind::LineComment | TokenKind::BlockComment { .. })
192-
).next();
192+
);
193193
if next_non_whitespace_token != Some(TokenKind::OpenBracket) {
194194
// No other choice than to consider this a shebang.
195195
return Some(2 + first_line_tail.len());

src/librustc_mir/const_eval/eval_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ pub fn const_eval_raw_provider<'tcx>(
309309

310310
let res = ecx.load_mir(cid.instance.def, cid.promoted);
311311
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body))
312-
.and_then(|place| {
313-
Ok(RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
314-
})
312+
.map(|place| RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
315313
.map_err(|error| {
316314
let err = error_to_const_error(&ecx, error);
317315
// errors in statics are always emitted as fatal errors

src/librustc_mir/transform/check_packed_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> {
5151
lint_root,
5252
source_info.span,
5353
|lint| {
54-
lint.build(&format!("reference to packed field is unaligned",))
54+
lint.build("reference to packed field is unaligned")
5555
.note(
5656
"fields of packed structs are not properly aligned, and creating \
5757
a misaligned reference is undefined behavior (even if that \

src/librustc_mir/transform/nrvo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> {
111111
copied_to_return_place = Some(returned_local);
112112
}
113113

114-
return copied_to_return_place;
114+
copied_to_return_place
115115
}
116116

117117
fn find_local_assigned_to_return_place(
@@ -136,7 +136,7 @@ fn find_local_assigned_to_return_place(
136136
}
137137
}
138138

139-
return None;
139+
None
140140
}
141141

142142
// If this statement is an assignment of an unprojected local to the return place,

src/librustc_mir/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option<ArmId
9999
fn try_eat<'a, 'tcx>(
100100
stmt_iter: &mut StmtIter<'a, 'tcx>,
101101
test: impl Fn(&'a Statement<'tcx>) -> bool,
102-
mut action: impl FnMut(usize, &'a Statement<'tcx>) -> (),
102+
mut action: impl FnMut(usize, &'a Statement<'tcx>),
103103
) {
104104
while stmt_iter.peek().map(|(_, stmt)| test(stmt)).unwrap_or(false) {
105105
let (idx, stmt) = stmt_iter.next().unwrap();
@@ -271,7 +271,7 @@ fn optimization_applies<'tcx>(
271271
}
272272

273273
// Verify the assigment chain consists of the form b = a; c = b; d = c; etc...
274-
if opt_info.field_tmp_assignments.len() == 0 {
274+
if opt_info.field_tmp_assignments.is_empty() {
275275
trace!("NO: no assignments found");
276276
}
277277
let mut last_assigned_to = opt_info.field_tmp_assignments[0].1;

src/librustc_parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a> StringReader<'a> {
409409
let content_end = suffix_start - BytePos(postfix_len);
410410
let id = self.symbol_from_to(content_start, content_end);
411411
self.validate_literal_escape(mode, content_start, content_end);
412-
return (lit_kind, id);
412+
(lit_kind, id)
413413
}
414414

415415
pub fn pos(&self) -> BytePos {

src/librustc_parse/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ impl<'a> Parser<'a> {
936936
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
937937
// The current token is in the same line as the prior token, not recoverable.
938938
} else if [token::Comma, token::Colon].contains(&self.token.kind)
939-
&& &self.prev_token.kind == &token::CloseDelim(token::Paren)
939+
&& self.prev_token.kind == token::CloseDelim(token::Paren)
940940
{
941941
// Likely typo: The current token is on a new line and is expected to be
942942
// `.`, `;`, `?`, or an operator after a close delimiter token.

src/librustc_parse/parser/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl TokenCursor {
193193
tree,
194194
self.stack.len()
195195
);
196-
collecting.buf.push(tree.clone().into())
196+
collecting.buf.push(tree.clone())
197197
}
198198
}
199199

@@ -675,7 +675,7 @@ impl<'a> Parser<'a> {
675675
// If this was a missing `@` in a binding pattern
676676
// bail with a suggestion
677677
// https://github.com/rust-lang/rust/issues/72373
678-
if self.prev_token.is_ident() && &self.token.kind == &token::DotDot {
678+
if self.prev_token.is_ident() && self.token.kind == token::DotDot {
679679
let msg = format!(
680680
"if you meant to bind the contents of \
681681
the rest of the array pattern into `{}`, use `@`",
@@ -1193,7 +1193,7 @@ impl<'a> Parser<'a> {
11931193
let mut collected_tokens = if let Some(collecting) = self.token_cursor.collecting.take() {
11941194
collecting.buf
11951195
} else {
1196-
let msg = format!("our vector went away?");
1196+
let msg = "our vector went away?";
11971197
debug!("collect_tokens: {}", msg);
11981198
self.sess.span_diagnostic.delay_span_bug(self.token.span, &msg);
11991199
// This can happen due to a bad interaction of two unrelated recovery mechanisms

src/librustc_passes/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl ExprVisitor<'tcx> {
232232
// size).
233233
if let Some((in_expr, Some(in_asm_ty))) = tied_input {
234234
if in_asm_ty != asm_ty {
235-
let msg = &format!("incompatible types for asm inout argument");
235+
let msg = "incompatible types for asm inout argument";
236236
let mut err = self.tcx.sess.struct_span_err(vec![in_expr.span, expr.span], msg);
237237
err.span_label(
238238
in_expr.span,

src/librustdoc/html/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> SourceCollector<'a> {
126126
&self.scx.themes,
127127
);
128128
self.scx.fs.write(&cur, v.as_bytes())?;
129-
self.scx.local_sources.insert(p.clone(), href);
129+
self.scx.local_sources.insert(p, href);
130130
Ok(())
131131
}
132132
}

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
451451
..
452452
},
453453
..
454-
})) => segments.first().and_then(|seg| Some(seg.ident.to_string())),
454+
})) => segments.first().map(|seg| seg.ident.to_string()),
455455
Some(hir::Node::Item(hir::Item {
456456
ident, kind: hir::ItemKind::Enum(..), ..
457457
}))

0 commit comments

Comments
 (0)