Skip to content

Commit 2cacc32

Browse files
authored
Rollup merge of #97424 - matthiaskrgr:clippy_complexity_may26, r=oli-obk
clippy::complexity fixes clone_on_copy useless_format bind_instead_of_map filter_map_identity useless_conversion map_flatten unnecessary_unwrap
2 parents f33601e + 5fc8a8e commit 2cacc32

File tree

11 files changed

+28
-45
lines changed

11 files changed

+28
-45
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1463,18 +1463,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14631463
if let GenericBound::Trait(ref poly, modify) = *bound {
14641464
match (ctxt, modify) {
14651465
(BoundKind::SuperTraits, TraitBoundModifier::Maybe) => {
1466-
let mut err = self.err_handler().struct_span_err(
1467-
poly.span,
1468-
&format!("`?Trait` is not permitted in supertraits"),
1469-
);
1466+
let mut err = self
1467+
.err_handler()
1468+
.struct_span_err(poly.span, "`?Trait` is not permitted in supertraits");
14701469
let path_str = pprust::path_to_string(&poly.trait_ref.path);
14711470
err.note(&format!("traits are `?{}` by default", path_str));
14721471
err.emit();
14731472
}
14741473
(BoundKind::TraitObject, TraitBoundModifier::Maybe) => {
14751474
let mut err = self.err_handler().struct_span_err(
14761475
poly.span,
1477-
&format!("`?Trait` is not permitted in trait object types"),
1476+
"`?Trait` is not permitted in trait object types",
14781477
);
14791478
err.emit();
14801479
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
450450
_ => None,
451451
};
452452

453-
if defined_hir.is_some() {
453+
if let Some(def_hir) = defined_hir {
454454
let upvars_map = self.infcx.tcx.upvars_mentioned(def_id).unwrap();
455-
let upvar_def_span = self.infcx.tcx.hir().span(defined_hir.unwrap());
456-
let upvar_span = upvars_map.get(&defined_hir.unwrap()).unwrap().span;
455+
let upvar_def_span = self.infcx.tcx.hir().span(def_hir);
456+
let upvar_span = upvars_map.get(&def_hir).unwrap().span;
457457
diag.span_label(upvar_def_span, "variable defined here");
458458
diag.span_label(upvar_span, "variable captured here");
459459
}

compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
462462
}
463463
};
464464
for elem in place_ref.projection[base..].iter() {
465-
cg_base = match elem.clone() {
465+
cg_base = match *elem {
466466
mir::ProjectionElem::Deref => {
467467
// a box with a non-zst allocator should not be directly dereferenced
468468
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
520520
frame
521521
.instance
522522
.try_subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value)
523-
.or_else(|e| {
523+
.map_err(|e| {
524524
self.tcx.sess.delay_span_bug(
525525
self.cur_span(),
526526
format!("failed to normalize {}", e.get_type_for_failure()).as_str(),
527527
);
528528

529-
Err(InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric))
529+
InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric)
530530
})
531531
}
532532

@@ -1009,11 +1009,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug
10091009
}
10101010
}
10111011

1012-
write!(
1013-
fmt,
1014-
": {:?}",
1015-
self.ecx.dump_allocs(allocs.into_iter().filter_map(|x| x).collect())
1016-
)
1012+
write!(fmt, ": {:?}", self.ecx.dump_allocs(allocs.into_iter().flatten().collect()))
10171013
}
10181014
Place::Ptr(mplace) => match mplace.ptr.provenance.and_then(Provenance::get_alloc_id) {
10191015
Some(alloc_id) => write!(

compiler/rustc_log/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
6969

7070
let verbose_entry_exit = match env::var_os(String::from(env) + "_ENTRY_EXIT") {
7171
None => false,
72-
Some(v) => {
73-
if &v == "0" {
74-
false
75-
} else {
76-
true
77-
}
78-
}
72+
Some(v) => &v != "0",
7973
};
8074

8175
let layer = tracing_tree::HierarchicalLayer::default()

compiler/rustc_middle/src/mir/patch.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ impl<'tcx> MirPatch<'tcx> {
167167
if loc.statement_index > body[loc.block].statements.len() {
168168
let term = body[loc.block].terminator();
169169
for i in term.successors() {
170-
stmts_and_targets
171-
.push((Statement { source_info, kind: stmt.clone() }, i.clone()));
170+
stmts_and_targets.push((Statement { source_info, kind: stmt.clone() }, i));
172171
}
173172
delta += 1;
174173
continue;

compiler/rustc_mir_build/src/build/expr/into.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
435435
}
436436
thir::InlineAsmOperand::SymFn { value, span } => {
437437
mir::InlineAsmOperand::SymFn {
438-
value: Box::new(Constant {
439-
span,
440-
user_ty: None,
441-
literal: value.into(),
442-
}),
438+
value: Box::new(Constant { span, user_ty: None, literal: value }),
443439
}
444440
}
445441
thir::InlineAsmOperand::SymStatic { def_id } => {

compiler/rustc_mir_build/src/build/matches/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
264264
);
265265
} else if let [success, fail] = *make_target_blocks(self) {
266266
assert_eq!(value.ty(), ty);
267-
let expect = self.literal_operand(test.span, value.into());
267+
let expect = self.literal_operand(test.span, value);
268268
let val = Operand::Copy(place);
269269
self.compare(block, success, fail, source_info, BinOp::Eq, expect, val);
270270
} else {
@@ -277,8 +277,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
277277
let target_blocks = make_target_blocks(self);
278278

279279
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
280-
let lo = self.literal_operand(test.span, lo.into());
281-
let hi = self.literal_operand(test.span, hi.into());
280+
let lo = self.literal_operand(test.span, lo);
281+
let hi = self.literal_operand(test.span, hi);
282282
let val = Operand::Copy(place);
283283

284284
let [success, fail] = *target_blocks else {
@@ -370,7 +370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
370370
place: Place<'tcx>,
371371
mut ty: Ty<'tcx>,
372372
) {
373-
let mut expect = self.literal_operand(source_info.span, value.into());
373+
let mut expect = self.literal_operand(source_info.span, value);
374374
let mut val = Operand::Copy(place);
375375

376376
// If we're using `b"..."` as a pattern, we need to insert an

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
845845
let first_provided_ty = if let Some((ty, _)) = final_arg_types[input_idx] {
846846
format!(",found `{}`", ty)
847847
} else {
848-
"".into()
848+
String::new()
849849
};
850850
labels.push((
851851
first_span,
@@ -857,7 +857,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857857
if let Some((ty, _)) = final_arg_types[other_input_idx] {
858858
format!(",found `{}`", ty)
859859
} else {
860-
"".into()
860+
String::new()
861861
};
862862
labels.push((
863863
second_span,
@@ -875,7 +875,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
875875
let provided_ty = if let Some((ty, _)) = final_arg_types[dst_arg] {
876876
format!(",found `{}`", ty)
877877
} else {
878-
"".into()
878+
String::new()
879879
};
880880
labels.push((
881881
provided_args[dst_arg].span,
@@ -1744,8 +1744,7 @@ fn label_fn_like<'tcx>(
17441744
.get_if_local(def_id)
17451745
.and_then(|node| node.body_id())
17461746
.into_iter()
1747-
.map(|id| tcx.hir().body(id).params)
1748-
.flatten();
1747+
.flat_map(|id| tcx.hir().body(id).params);
17491748

17501749
for param in params {
17511750
spans.push_span_label(param.span, String::new());

compiler/rustc_typeck/src/check/method/suggest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
Obligation {
493493
cause: cause.clone(),
494494
param_env: self.param_env,
495-
predicate: predicate.clone(),
495+
predicate: *predicate,
496496
recursion_depth: 0,
497497
},
498498
));
@@ -676,7 +676,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
676676
let span = self_ty.span.ctxt().outer_expn_data().call_site;
677677
let mut spans: MultiSpan = span.into();
678678
spans.push_span_label(span, derive_msg.to_string());
679-
let entry = spanned_predicates.entry(spans.into());
679+
let entry = spanned_predicates.entry(spans);
680680
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
681681
}
682682

@@ -704,7 +704,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
704704
ident.span.into()
705705
};
706706
spans.push_span_label(ident.span, "in this trait".to_string());
707-
let entry = spanned_predicates.entry(spans.into());
707+
let entry = spanned_predicates.entry(spans);
708708
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
709709
}
710710

@@ -748,7 +748,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
748748
}
749749
spans.push_span_label(self_ty.span, String::new());
750750

751-
let entry = spanned_predicates.entry(spans.into());
751+
let entry = spanned_predicates.entry(spans);
752752
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
753753
}
754754
_ => {}
@@ -1460,7 +1460,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14601460
{
14611461
derives.push((
14621462
self_name.clone(),
1463-
self_span.clone(),
1463+
self_span,
14641464
parent_diagnostic_name.to_string(),
14651465
));
14661466
}

compiler/rustc_typeck/src/check/op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
705705
let predicates = errors
706706
.iter()
707707
.filter_map(|error| {
708-
error.obligation.predicate.clone().to_opt_poly_trait_pred()
708+
error.obligation.predicate.to_opt_poly_trait_pred()
709709
});
710710
for pred in predicates {
711711
self.infcx.suggest_restricting_param_bound(

0 commit comments

Comments
 (0)