Skip to content

Commit 6bdb8a4

Browse files
committed
Auto merge of rust-lang#121523 - matthiaskrgr:comp_comp, r=Nilstrieb
compiler: clippy::complexity fixes
2 parents 8f359be + 86a7fc8 commit 6bdb8a4

File tree

23 files changed

+62
-95
lines changed

23 files changed

+62
-95
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
138138
} else {
139139
self.tcx.fn_arg_names(sig_id).len()
140140
};
141-
let inputs = self.arena.alloc_from_iter((0..args_count).into_iter().map(|arg| hir::Ty {
141+
let inputs = self.arena.alloc_from_iter((0..args_count).map(|arg| hir::Ty {
142142
hir_id: self.next_id(),
143143
kind: hir::TyKind::InferDelegation(sig_id, hir::InferDelegationKind::Input(arg)),
144144
span: self.lower_span(param_span),

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15591559
// A bare path doesn't need a `let` assignment, it's already a simple
15601560
// binding access.
15611561
// As a new binding wasn't added, we don't need to modify the advancing call.
1562-
sugg.push((loop_span.with_hi(pat_span.lo()), format!("while let Some(")));
1562+
sugg.push((loop_span.with_hi(pat_span.lo()), "while let Some(".to_string()));
15631563
sugg.push((
15641564
pat_span.shrink_to_hi().with_hi(head.span.lo()),
15651565
") = ".to_string(),

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ impl OutlivesSuggestionBuilder {
134134

135135
for (r, bound) in unified.into_iter() {
136136
if !unified_already.contains(fr) {
137-
suggested.push(SuggestedConstraint::Equal(fr_name.clone(), bound));
137+
suggested.push(SuggestedConstraint::Equal(fr_name, bound));
138138
unified_already.insert(r);
139139
}
140140
}
141141

142142
if !other.is_empty() {
143-
let other =
144-
other.iter().map(|(_, rname)| rname.clone()).collect::<SmallVec<_>>();
143+
let other = other.iter().map(|(_, rname)| *rname).collect::<SmallVec<_>>();
145144
suggested.push(SuggestedConstraint::Outlives(fr_name, other))
146145
}
147146
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
280280
.iter()
281281
.rfind(|param| param.def_id.to_def_id() == defid)
282282
.is_some() {
283-
suggestions.push((bounded_span.shrink_to_hi(), format!(" + 'static")));
283+
suggestions.push((bounded_span.shrink_to_hi(), " + 'static".to_string()));
284284
}
285285
});
286286
});

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn intern_const_alloc_recursive<
140140
alloc.1.mutability = base_mutability;
141141
alloc.1.provenance().ptrs().iter().map(|&(_, prov)| prov).collect()
142142
} else {
143-
intern_shallow(ecx, base_alloc_id, base_mutability).unwrap().map(|prov| prov).collect()
143+
intern_shallow(ecx, base_alloc_id, base_mutability).unwrap().collect()
144144
};
145145
// We need to distinguish "has just been interned" from "was already in `tcx`",
146146
// so we track this in a separate set.
@@ -277,7 +277,7 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
277277
// We are not doing recursive interning, so we don't currently support provenance.
278278
// (If this assertion ever triggers, we should just implement a
279279
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.
280-
if !self.tcx.try_get_global_alloc(prov.alloc_id()).is_some() {
280+
if self.tcx.try_get_global_alloc(prov.alloc_id()).is_none() {
281281
panic!("`intern_with_temp_alloc` with nested allocations");
282282
}
283283
}

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl DiagCtxt {
844844
.emitted_diagnostic_codes
845845
.iter()
846846
.filter_map(|&code| {
847-
if registry.try_find_description(code).is_ok().clone() {
847+
if registry.try_find_description(code).is_ok() {
848848
Some(code.to_string())
849849
} else {
850850
None

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -555,23 +555,14 @@ fn count_repetitions<'a>(
555555
) -> PResult<'a, usize> {
556556
// Recursively count the number of matches in `matched` at given depth
557557
// (or at the top-level of `matched` if no depth is given).
558-
fn count<'a>(
559-
cx: &ExtCtxt<'a>,
560-
depth_curr: usize,
561-
depth_max: usize,
562-
matched: &NamedMatch,
563-
sp: &DelimSpan,
564-
) -> PResult<'a, usize> {
558+
fn count<'a>(depth_curr: usize, depth_max: usize, matched: &NamedMatch) -> PResult<'a, usize> {
565559
match matched {
566560
MatchedTokenTree(_) | MatchedNonterminal(_) => Ok(1),
567561
MatchedSeq(named_matches) => {
568562
if depth_curr == depth_max {
569563
Ok(named_matches.len())
570564
} else {
571-
named_matches
572-
.iter()
573-
.map(|elem| count(cx, depth_curr + 1, depth_max, elem, sp))
574-
.sum()
565+
named_matches.iter().map(|elem| count(depth_curr + 1, depth_max, elem)).sum()
575566
}
576567
}
577568
}
@@ -612,7 +603,7 @@ fn count_repetitions<'a>(
612603
return Err(cx.dcx().create_err(CountRepetitionMisplaced { span: sp.entire() }));
613604
}
614605

615-
count(cx, depth_user, depth_max, matched, sp)
606+
count(depth_user, depth_max, matched)
616607
}
617608

618609
/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
401401
{
402402
// check that the `if` expr without `else` is the fn body's expr
403403
if expr.span == sp {
404-
return self.get_fn_decl(hir_id).and_then(|(_, fn_decl, _)| {
404+
return self.get_fn_decl(hir_id).map(|(_, fn_decl, _)| {
405405
let (ty, span) = match fn_decl.output {
406406
hir::FnRetTy::DefaultReturn(span) => ("()".to_string(), span),
407407
hir::FnRetTy::Return(ty) => (ty_to_string(ty), ty.span),
408408
};
409-
Some((span, format!("expected `{ty}` because of this return type")))
409+
(span, format!("expected `{ty}` because of this return type"))
410410
});
411411
}
412412
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
846846
let item_name = item_segment.ident;
847847
let result = self
848848
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
849-
.and_then(|r| {
849+
.map(|r| {
850850
// lint bare trait if the method is found in the trait
851851
if span.edition().at_least_rust_2021()
852852
&& let Some(diag) =
853853
self.dcx().steal_diagnostic(qself.span, StashKey::TraitMissingMethod)
854854
{
855855
diag.emit();
856856
}
857-
Ok(r)
857+
r
858858
})
859859
.or_else(|error| {
860860
let guar = self

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
555555
{
556556
let args = self.infcx.fresh_args_for_item(call_name.span, assoc.def_id);
557557
let fn_sig = tcx.fn_sig(assoc.def_id).instantiate(tcx, args);
558-
let fn_sig =
559-
self.instantiate_binder_with_fresh_vars(call_name.span, FnCall, fn_sig);
560-
Some((assoc, fn_sig));
558+
559+
self.instantiate_binder_with_fresh_vars(call_name.span, FnCall, fn_sig);
561560
}
562561
None
563562
};

0 commit comments

Comments
 (0)