Auto merge of #121523 - matthiaskrgr:comp_comp, r=Nilstrieb

compiler: clippy::complexity fixes
This commit is contained in:
bors 2024-02-24 19:07:20 +00:00
commit 6bdb8a4a96
23 changed files with 62 additions and 95 deletions

View File

@ -138,7 +138,7 @@ fn lower_delegation_decl(
} else {
self.tcx.fn_arg_names(sig_id).len()
};
let inputs = self.arena.alloc_from_iter((0..args_count).into_iter().map(|arg| hir::Ty {
let inputs = self.arena.alloc_from_iter((0..args_count).map(|arg| hir::Ty {
hir_id: self.next_id(),
kind: hir::TyKind::InferDelegation(sig_id, hir::InferDelegationKind::Input(arg)),
span: self.lower_span(param_span),

View File

@ -1559,7 +1559,7 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
// A bare path doesn't need a `let` assignment, it's already a simple
// binding access.
// As a new binding wasn't added, we don't need to modify the advancing call.
sugg.push((loop_span.with_hi(pat_span.lo()), format!("while let Some(")));
sugg.push((loop_span.with_hi(pat_span.lo()), "while let Some(".to_string()));
sugg.push((
pat_span.shrink_to_hi().with_hi(head.span.lo()),
") = ".to_string(),

View File

@ -134,14 +134,13 @@ fn compile_all_suggestions(
for (r, bound) in unified.into_iter() {
if !unified_already.contains(fr) {
suggested.push(SuggestedConstraint::Equal(fr_name.clone(), bound));
suggested.push(SuggestedConstraint::Equal(fr_name, bound));
unified_already.insert(r);
}
}
if !other.is_empty() {
let other =
other.iter().map(|(_, rname)| rname.clone()).collect::<SmallVec<_>>();
let other = other.iter().map(|(_, rname)| *rname).collect::<SmallVec<_>>();
suggested.push(SuggestedConstraint::Outlives(fr_name, other))
}
}

View File

@ -280,7 +280,7 @@ fn suggest_static_lifetime_for_gat_from_hrtb(
.iter()
.rfind(|param| param.def_id.to_def_id() == defid)
.is_some() {
suggestions.push((bounded_span.shrink_to_hi(), format!(" + 'static")));
suggestions.push((bounded_span.shrink_to_hi(), " + 'static".to_string()));
}
});
});

View File

@ -140,7 +140,7 @@ pub fn intern_const_alloc_recursive<
alloc.1.mutability = base_mutability;
alloc.1.provenance().ptrs().iter().map(|&(_, prov)| prov).collect()
} else {
intern_shallow(ecx, base_alloc_id, base_mutability).unwrap().map(|prov| prov).collect()
intern_shallow(ecx, base_alloc_id, base_mutability).unwrap().collect()
};
// We need to distinguish "has just been interned" from "was already in `tcx`",
// so we track this in a separate set.
@ -277,7 +277,7 @@ pub fn intern_with_temp_alloc(
// We are not doing recursive interning, so we don't currently support provenance.
// (If this assertion ever triggers, we should just implement a
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.
if !self.tcx.try_get_global_alloc(prov.alloc_id()).is_some() {
if self.tcx.try_get_global_alloc(prov.alloc_id()).is_none() {
panic!("`intern_with_temp_alloc` with nested allocations");
}
}

View File

@ -844,7 +844,7 @@ pub fn print_error_count(&self, registry: &Registry) {
.emitted_diagnostic_codes
.iter()
.filter_map(|&code| {
if registry.try_find_description(code).is_ok().clone() {
if registry.try_find_description(code).is_ok() {
Some(code.to_string())
} else {
None

View File

@ -555,23 +555,14 @@ fn count_repetitions<'a>(
) -> PResult<'a, usize> {
// Recursively count the number of matches in `matched` at given depth
// (or at the top-level of `matched` if no depth is given).
fn count<'a>(
cx: &ExtCtxt<'a>,
depth_curr: usize,
depth_max: usize,
matched: &NamedMatch,
sp: &DelimSpan,
) -> PResult<'a, usize> {
fn count<'a>(depth_curr: usize, depth_max: usize, matched: &NamedMatch) -> PResult<'a, usize> {
match matched {
MatchedTokenTree(_) | MatchedNonterminal(_) => Ok(1),
MatchedSeq(named_matches) => {
if depth_curr == depth_max {
Ok(named_matches.len())
} else {
named_matches
.iter()
.map(|elem| count(cx, depth_curr + 1, depth_max, elem, sp))
.sum()
named_matches.iter().map(|elem| count(depth_curr + 1, depth_max, elem)).sum()
}
}
}
@ -612,7 +603,7 @@ fn depth(counter: usize, matched: &NamedMatch) -> usize {
return Err(cx.dcx().create_err(CountRepetitionMisplaced { span: sp.entire() }));
}
count(cx, depth_user, depth_max, matched, sp)
count(depth_user, depth_max, matched)
}
/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]

View File

@ -401,12 +401,12 @@ pub fn maybe_get_coercion_reason(
{
// check that the `if` expr without `else` is the fn body's expr
if expr.span == sp {
return self.get_fn_decl(hir_id).and_then(|(_, fn_decl, _)| {
return self.get_fn_decl(hir_id).map(|(_, fn_decl, _)| {
let (ty, span) = match fn_decl.output {
hir::FnRetTy::DefaultReturn(span) => ("()".to_string(), span),
hir::FnRetTy::Return(ty) => (ty_to_string(ty), ty.span),
};
Some((span, format!("expected `{ty}` because of this return type")))
(span, format!("expected `{ty}` because of this return type"))
});
}
}

View File

@ -846,7 +846,7 @@ pub fn resolve_ty_and_res_fully_qualified_call(
let item_name = item_segment.ident;
let result = self
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
.and_then(|r| {
.map(|r| {
// lint bare trait if the method is found in the trait
if span.edition().at_least_rust_2021()
&& let Some(diag) =
@ -854,7 +854,7 @@ pub fn resolve_ty_and_res_fully_qualified_call(
{
diag.emit();
}
Ok(r)
r
})
.or_else(|error| {
let guar = self

View File

@ -555,9 +555,8 @@ fn has_error_or_infer<'tcx>(tys: impl IntoIterator<Item = Ty<'tcx>>) -> bool {
{
let args = self.infcx.fresh_args_for_item(call_name.span, assoc.def_id);
let fn_sig = tcx.fn_sig(assoc.def_id).instantiate(tcx, args);
let fn_sig =
self.instantiate_binder_with_fresh_vars(call_name.span, FnCall, fn_sig);
Some((assoc, fn_sig));
self.instantiate_binder_with_fresh_vars(call_name.span, FnCall, fn_sig);
}
None
};

View File

@ -1061,20 +1061,15 @@ pub(in super::super) fn suggest_missing_break_or_return_expr(
return;
}
let scope = self
.tcx
.hir()
.parent_iter(id)
.filter(|(_, node)| {
matches!(
node,
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
| Node::Item(_)
| Node::TraitItem(_)
| Node::ImplItem(_)
)
})
.next();
let scope = self.tcx.hir().parent_iter(id).find(|(_, node)| {
matches!(
node,
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
| Node::Item(_)
| Node::TraitItem(_)
| Node::ImplItem(_)
)
});
let in_closure =
matches!(scope, Some((_, Node::Expr(Expr { kind: ExprKind::Closure(..), .. }))));

View File

@ -370,9 +370,7 @@ fn suggest_missing_writer(
};
if let Some(file) = file {
err.note(format!("the full type name has been written to '{}'", file.display()));
err.note(format!(
"consider using `--verbose` to print the full type name to the console"
));
err.note("consider using `--verbose` to print the full type name to the console");
}
err
@ -497,9 +495,7 @@ pub fn report_no_match_method_error(
if let Some(file) = ty_file {
err.note(format!("the full type name has been written to '{}'", file.display(),));
err.note(format!(
"consider using `--verbose` to print the full type name to the console"
));
err.note("consider using `--verbose` to print the full type name to the console");
}
if rcvr_ty.references_error() {
err.downgrade_to_delayed_bug();

View File

@ -2035,7 +2035,7 @@ fn try_resolve_slice_ty_to_array_ty(
slice: Option<&'tcx Pat<'tcx>>,
span: Span,
) -> Option<Ty<'tcx>> {
if !slice.is_none() {
if slice.is_some() {
return None;
}

View File

@ -1938,7 +1938,7 @@ enum Similar<'tcx> {
"the full type name has been written to '{}'",
path.display(),
));
diag.note(format!("consider using `--verbose` to print the full type name to the console"));
diag.note("consider using `--verbose` to print the full type name to the console");
}
}
}

View File

@ -139,7 +139,7 @@ fn default_print_def_path(
_,
hir::CoroutineSource::Closure,
)) = self.tcx().coroutine_kind(def_id)
&& args.len() >= parent_args.len() + 1
&& args.len() > parent_args.len()
{
return self.path_generic_args(
|cx| cx.print_def_path(def_id, parent_args),

View File

@ -223,19 +223,14 @@ fn lower_pattern_range(
// If we are handling a range with associated constants (e.g.
// `Foo::<'a>::A..=Foo::B`), we need to put the ascriptions for the associated
// constants somewhere. Have them on the range pattern.
for ascr in [lo_ascr, hi_ascr] {
if let Some(ascription) = ascr {
kind = PatKind::AscribeUserType {
ascription,
subpattern: Box::new(Pat { span, ty, kind }),
};
}
for ascription in [lo_ascr, hi_ascr].into_iter().flatten() {
kind = PatKind::AscribeUserType {
ascription,
subpattern: Box::new(Pat { span, ty, kind }),
};
}
for inline_const in [lo_inline, hi_inline] {
if let Some(def) = inline_const {
kind =
PatKind::InlineConstant { def, subpattern: Box::new(Pat { span, ty, kind }) };
}
for def in [lo_inline, hi_inline].into_iter().flatten() {
kind = PatKind::InlineConstant { def, subpattern: Box::new(Pat { span, ty, kind }) };
}
Ok(kind)
}

View File

@ -88,7 +88,7 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
// results in `ast::ExprKind::Err`. In that case we delay
// the error because an earlier error will have already
// been reported.
let msg = format!("attribute value must be a literal");
let msg = "attribute value must be a literal";
let mut err = sess.dcx.struct_span_err(expr.span, msg);
if let ast::ExprKind::Err = expr.kind {
err.downgrade_to_delayed_bug();

View File

@ -694,18 +694,14 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
fn clone(&self) -> Self {
match self {
Constructor::Struct => Constructor::Struct,
Constructor::Variant(idx) => Constructor::Variant(idx.clone()),
Constructor::Variant(idx) => Constructor::Variant(*idx),
Constructor::Ref => Constructor::Ref,
Constructor::Slice(slice) => Constructor::Slice(slice.clone()),
Constructor::Slice(slice) => Constructor::Slice(*slice),
Constructor::UnionField => Constructor::UnionField,
Constructor::Bool(b) => Constructor::Bool(b.clone()),
Constructor::IntRange(range) => Constructor::IntRange(range.clone()),
Constructor::F32Range(lo, hi, end) => {
Constructor::F32Range(lo.clone(), hi.clone(), end.clone())
}
Constructor::F64Range(lo, hi, end) => {
Constructor::F64Range(lo.clone(), hi.clone(), end.clone())
}
Constructor::Bool(b) => Constructor::Bool(*b),
Constructor::IntRange(range) => Constructor::IntRange(*range),
Constructor::F32Range(lo, hi, end) => Constructor::F32Range(lo.clone(), *hi, *end),
Constructor::F64Range(lo, hi, end) => Constructor::F64Range(lo.clone(), *hi, *end),
Constructor::Str(value) => Constructor::Str(value.clone()),
Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()),
Constructor::Or => Constructor::Or,

View File

@ -1582,7 +1582,7 @@ fn smart_resolve_context_dependent_help(
None => ("/* fields */".to_string(), Applicability::HasPlaceholders),
};
let pad = match field_ids {
Some(field_ids) if field_ids.is_empty() => "",
Some([]) => "",
_ => " ",
};
err.span_suggestion(

View File

@ -1264,7 +1264,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
// LLVM CFI using rustc LTO requires a single codegen unit.
if sess.is_sanitizer_cfi_enabled()
&& sess.lto() == config::Lto::Fat
&& !(sess.codegen_units().as_usize() == 1)
&& (sess.codegen_units().as_usize() != 1)
{
sess.dcx().emit_err(errors::SanitizerCfiRequiresSingleCodegenUnit);
}

View File

@ -208,11 +208,10 @@ fn find_crates(&self, name: &str) -> Vec<stable_mir::Crate> {
let crates: Vec<stable_mir::Crate> = [LOCAL_CRATE]
.iter()
.chain(tables.tcx.crates(()).iter())
.map(|crate_num| {
.filter_map(|crate_num| {
let crate_name = tables.tcx.crate_name(*crate_num).to_string();
(name == crate_name).then(|| smir_crate(tables.tcx, *crate_num))
})
.flatten()
.collect();
crates
}

View File

@ -1283,9 +1283,9 @@ fn suggest_add_reference_to_arg(
"the full type name has been written to '{}'",
file.display()
));
err.note(format!(
"consider using `--verbose` to print full type name to the console"
));
err.note(
"consider using `--verbose` to print full type name to the console",
);
}
if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
@ -2869,9 +2869,9 @@ fn note_obligation_cause_code<G: EmissionGuarantee, T>(
"the full name for the type has been written to '{}'",
file.display(),
));
err.note(format!(
"consider using `--verbose` to print the full type name to the console"
));
err.note(
"consider using `--verbose` to print the full type name to the console",
);
}
}
ObligationCauseCode::RepeatElementCopy {
@ -3339,9 +3339,9 @@ fn note_obligation_cause_code<G: EmissionGuarantee, T>(
"the full type name has been written to '{}'",
file.display(),
));
err.note(format!(
"consider using `--verbose` to print the full type name to the console"
));
err.note(
"consider using `--verbose` to print the full type name to the console",
);
}
let mut parent_predicate = parent_trait_pred;
let mut data = &data.derived;
@ -3395,9 +3395,9 @@ fn note_obligation_cause_code<G: EmissionGuarantee, T>(
"the full type name has been written to '{}'",
file.display(),
));
err.note(format!(
"consider using `--verbose` to print the full type name to the console"
));
err.note(
"consider using `--verbose` to print the full type name to the console",
);
}
}
// #74711: avoid a stack overflow

View File

@ -1031,12 +1031,9 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
{
candidate_set.mark_ambiguous();
true
} else if obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
&& obligation.predicate.args.type_at(1).to_opt_closure_kind().is_some()
{
true
} else {
false
obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
&& obligation.predicate.args.type_at(1).to_opt_closure_kind().is_some()
}
} else if lang_items.discriminant_kind_trait() == Some(trait_ref.def_id) {
match self_ty.kind() {