Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkin

more clippy::complexity fixes

      redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
This commit is contained in:
Jubilee 2023-12-12 18:48:54 -08:00 committed by GitHub
commit 4583a0134f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 18 additions and 28 deletions

View file

@ -1701,7 +1701,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
&& !ty.is_never() && !ty.is_never()
{ {
let indentation = if let None = block.expr let indentation = if let None = block.expr
&& let [.., last] = &block.stmts[..] && let [.., last] = &block.stmts
{ {
tcx.sess.source_map().indentation_before(last.span).unwrap_or_else(String::new) tcx.sess.source_map().indentation_before(last.span).unwrap_or_else(String::new)
} else if let Some(expr) = block.expr { } else if let Some(expr) = block.expr {
@ -1710,7 +1710,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
String::new() String::new()
}; };
if let None = block.expr if let None = block.expr
&& let [.., last] = &block.stmts[..] && let [.., last] = &block.stmts
{ {
err.span_suggestion_verbose( err.span_suggestion_verbose(
last.span.shrink_to_hi(), last.span.shrink_to_hi(),
@ -1750,7 +1750,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
} }
} }
if let None = block.expr if let None = block.expr
&& let [.., last] = &block.stmts[..] && let [.., last] = &block.stmts
{ {
sugg.push((last.span.shrink_to_hi(), format!("\n{indentation}None"))); sugg.push((last.span.shrink_to_hi(), format!("\n{indentation}None")));
} else if let Some(expr) = block.expr { } else if let Some(expr) = block.expr {

View file

@ -862,7 +862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
mutability, mutability,
), ),
), ),
match &args[..] { match &args {
[] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()), [] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()),
[first, ..] => (base.span.between(first.span), ", ".to_string()), [first, ..] => (base.span.between(first.span), ", ".to_string()),
}, },

View file

@ -2452,7 +2452,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if !suggs.is_empty() { if !suggs.is_empty() {
err.multipart_suggestion_verbose( err.multipart_suggestion_verbose(
format!("{msg}"), msg,
suggs, suggs,
Applicability::MaybeIncorrect, // Issue #41966 Applicability::MaybeIncorrect, // Issue #41966
); );

View file

@ -174,7 +174,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
span: Span, span: Span,
) -> Result<PatKind<'tcx>, ErrorGuaranteed> { ) -> Result<PatKind<'tcx>, ErrorGuaranteed> {
if lo_expr.is_none() && hi_expr.is_none() { if lo_expr.is_none() && hi_expr.is_none() {
let msg = format!("found twice-open range pattern (`..`) outside of error recovery"); let msg = "found twice-open range pattern (`..`) outside of error recovery";
return Err(self.tcx.sess.span_delayed_bug(span, msg)); return Err(self.tcx.sess.span_delayed_bug(span, msg));
} }

View file

@ -1063,12 +1063,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
initial_binding.res() initial_binding.res()
}); });
let res = binding.res(); let res = binding.res();
let has_ambiguity_error = this let has_ambiguity_error =
.ambiguity_errors this.ambiguity_errors.iter().any(|error| !error.warning);
.iter()
.filter(|error| !error.warning)
.next()
.is_some();
if res == Res::Err || has_ambiguity_error { if res == Res::Err || has_ambiguity_error {
this.tcx this.tcx
.sess .sess

View file

@ -1829,13 +1829,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
) )
.iter() .iter()
.filter_map(|candidate| candidate.did) .filter_map(|candidate| candidate.did)
.filter(|did| { .find(|did| {
self.r self.r
.tcx .tcx
.get_attrs(*did, sym::rustc_diagnostic_item) .get_attrs(*did, sym::rustc_diagnostic_item)
.any(|attr| attr.value_str() == Some(sym::Default)) .any(|attr| attr.value_str() == Some(sym::Default))
}) });
.next();
let Some(default_trait) = default_trait else { let Some(default_trait) = default_trait else {
return; return;
}; };
@ -1880,11 +1879,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}; };
fields.is_some_and(|fields| { fields.is_some_and(|fields| {
fields fields.iter().any(|vis| !self.r.is_accessible_from(*vis, self.parent_scope.module))
.iter()
.filter(|vis| !self.r.is_accessible_from(**vis, self.parent_scope.module))
.next()
.is_some()
}) })
} }

View file

@ -707,7 +707,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> {
let id = tables.intern_const(*self); let id = tables.intern_const(*self);
Const::new(kind, ty, id) Const::new(kind, ty, id)
} }
mir::Const::Val(val, ty) if matches!(val, mir::ConstValue::ZeroSized) => { mir::Const::Val(mir::ConstValue::ZeroSized, ty) => {
let ty = ty.stable(tables); let ty = ty.stable(tables);
let id = tables.intern_const(*self); let id = tables.intern_const(*self);
Const::new(ConstantKind::ZeroSized, ty, id) Const::new(ConstantKind::ZeroSized, ty, id)

View file

@ -101,11 +101,10 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
self.tcx.impl_trait_ref(impl_def_id).map(|r| (impl_def_id, r)) self.tcx.impl_trait_ref(impl_def_id).map(|r| (impl_def_id, r))
}) })
.map(|(impl_def_id, imp)| (impl_def_id, imp.skip_binder())) .map(|(impl_def_id, imp)| (impl_def_id, imp.skip_binder()))
.filter(|(_, imp)| match imp.self_ty().peel_refs().kind() { .find(|(_, imp)| match imp.self_ty().peel_refs().kind() {
ty::Adt(i_def, _) if i_def.did() == def.did() => true, ty::Adt(i_def, _) if i_def.did() == def.did() => true,
_ => false, _ => false,
}) })
.next()
{ {
let mut fulfill_cx = FulfillmentCtxt::new(self); let mut fulfill_cx = FulfillmentCtxt::new(self);
// We get all obligations from the impl to talk about specific // We get all obligations from the impl to talk about specific

View file

@ -2167,7 +2167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}) })
.collect(); .collect();
err.multipart_suggestion( err.multipart_suggestion(
format!("consider wrapping the function in a closure"), "consider wrapping the function in a closure",
vec![ vec![
(arg.span.shrink_to_lo(), format!("|{}| ", closure_names.join(", "))), (arg.span.shrink_to_lo(), format!("|{}| ", closure_names.join(", "))),
(arg.span.shrink_to_hi(), format!("({})", call_names.join(", "))), (arg.span.shrink_to_hi(), format!("({})", call_names.join(", "))),

View file

@ -2245,8 +2245,8 @@ impl GenericArgs {
} }
pub(crate) fn bindings<'a>(&'a self) -> Box<dyn Iterator<Item = TypeBinding> + 'a> { pub(crate) fn bindings<'a>(&'a self) -> Box<dyn Iterator<Item = TypeBinding> + 'a> {
match self { match self {
&GenericArgs::AngleBracketed { ref bindings, .. } => Box::new(bindings.iter().cloned()), GenericArgs::AngleBracketed { bindings, .. } => Box::new(bindings.iter().cloned()),
&GenericArgs::Parenthesized { ref output, .. } => Box::new( GenericArgs::Parenthesized { output, .. } => Box::new(
output output
.as_ref() .as_ref()
.map(|ty| TypeBinding { .map(|ty| TypeBinding {
@ -2270,8 +2270,8 @@ impl<'a> IntoIterator for &'a GenericArgs {
type Item = GenericArg; type Item = GenericArg;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
match self { match self {
&GenericArgs::AngleBracketed { ref args, .. } => Box::new(args.iter().cloned()), GenericArgs::AngleBracketed { args, .. } => Box::new(args.iter().cloned()),
&GenericArgs::Parenthesized { ref inputs, .. } => { GenericArgs::Parenthesized { inputs, .. } => {
Box::new(inputs.iter().cloned().map(GenericArg::Type)) Box::new(inputs.iter().cloned().map(GenericArg::Type))
} }
} }