Skip to content

Commit 58023fe

Browse files
committed
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
1 parent feb3536 commit 58023fe

File tree

18 files changed

+25
-34
lines changed

18 files changed

+25
-34
lines changed

src/librustc_ast/tokenstream.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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 \

0 commit comments

Comments
 (0)