From 3795cc8eb04b5b95c6a7a8dd7bcf357adb01169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 12 Dec 2023 20:41:51 +0100 Subject: [PATCH] more clippy::complexity fixes redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format --- compiler/rustc_hir_typeck/src/coercion.rs | 6 +++--- compiler/rustc_hir_typeck/src/demand.rs | 2 +- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 8 ++------ compiler/rustc_resolve/src/late/diagnostics.rs | 11 +++-------- compiler/rustc_smir/src/rustc_smir/convert/mir.rs | 2 +- compiler/rustc_trait_selection/src/infer.rs | 3 +-- .../src/traits/error_reporting/suggestions.rs | 2 +- src/librustdoc/clean/types.rs | 8 ++++---- 10 files changed, 18 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 0d3bb0f7e0c..f697182e45a 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1701,7 +1701,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { && !ty.is_never() { 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) } else if let Some(expr) = block.expr { @@ -1710,7 +1710,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { String::new() }; if let None = block.expr - && let [.., last] = &block.stmts[..] + && let [.., last] = &block.stmts { err.span_suggestion_verbose( last.span.shrink_to_hi(), @@ -1750,7 +1750,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { } } if let None = block.expr - && let [.., last] = &block.stmts[..] + && let [.., last] = &block.stmts { sugg.push((last.span.shrink_to_hi(), format!("\n{indentation}None"))); } else if let Some(expr) = block.expr { diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 8f633834885..f2301407813 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -862,7 +862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { mutability, ), ), - match &args[..] { + match &args { [] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()), [first, ..] => (base.span.between(first.span), ", ".to_string()), }, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 745c3d195ad..e568ff9f282 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2452,7 +2452,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if !suggs.is_empty() { err.multipart_suggestion_verbose( - format!("{msg}"), + msg, suggs, Applicability::MaybeIncorrect, // Issue #41966 ); diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index af0dab4ebc7..c7762f8ce4e 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { span: Span, ) -> Result, ErrorGuaranteed> { 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)); } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index e601ceaa50c..39e82da6d9d 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1063,12 +1063,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { initial_binding.res() }); let res = binding.res(); - let has_ambiguity_error = this - .ambiguity_errors - .iter() - .filter(|error| !error.warning) - .next() - .is_some(); + let has_ambiguity_error = + this.ambiguity_errors.iter().any(|error| !error.warning); if res == Res::Err || has_ambiguity_error { this.tcx .sess diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index df30c185c60..3bd6b0f1d77 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1829,13 +1829,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { ) .iter() .filter_map(|candidate| candidate.did) - .filter(|did| { + .find(|did| { self.r .tcx .get_attrs(*did, sym::rustc_diagnostic_item) .any(|attr| attr.value_str() == Some(sym::Default)) - }) - .next(); + }); let Some(default_trait) = default_trait else { return; }; @@ -1880,11 +1879,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { }; fields.is_some_and(|fields| { - fields - .iter() - .filter(|vis| !self.r.is_accessible_from(**vis, self.parent_scope.module)) - .next() - .is_some() + fields.iter().any(|vis| !self.r.is_accessible_from(*vis, self.parent_scope.module)) }) } diff --git a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs index 0cea3fcc7f7..8c1767501d9 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs @@ -707,7 +707,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { let id = tables.intern_const(*self); 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 id = tables.intern_const(*self); Const::new(ConstantKind::ZeroSized, ty, id) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 4b11cc3ace9..251f0628a71 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -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)) }) .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, _ => false, }) - .next() { let mut fulfill_cx = FulfillmentCtxt::new(self); // We get all obligations from the impl to talk about specific diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index f7e8dc62a62..1033fe68140 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2167,7 +2167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { }) .collect(); err.multipart_suggestion( - format!("consider wrapping the function in a closure"), + "consider wrapping the function in a closure", vec![ (arg.span.shrink_to_lo(), format!("|{}| ", closure_names.join(", "))), (arg.span.shrink_to_hi(), format!("({})", call_names.join(", "))), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 0a14404d689..150625c6d92 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2245,8 +2245,8 @@ impl GenericArgs { } pub(crate) fn bindings<'a>(&'a self) -> Box + 'a> { match self { - &GenericArgs::AngleBracketed { ref bindings, .. } => Box::new(bindings.iter().cloned()), - &GenericArgs::Parenthesized { ref output, .. } => Box::new( + GenericArgs::AngleBracketed { bindings, .. } => Box::new(bindings.iter().cloned()), + GenericArgs::Parenthesized { output, .. } => Box::new( output .as_ref() .map(|ty| TypeBinding { @@ -2270,8 +2270,8 @@ impl<'a> IntoIterator for &'a GenericArgs { type Item = GenericArg; fn into_iter(self) -> Self::IntoIter { match self { - &GenericArgs::AngleBracketed { ref args, .. } => Box::new(args.iter().cloned()), - &GenericArgs::Parenthesized { ref inputs, .. } => { + GenericArgs::AngleBracketed { args, .. } => Box::new(args.iter().cloned()), + GenericArgs::Parenthesized { inputs, .. } => { Box::new(inputs.iter().cloned().map(GenericArg::Type)) } }