Skip to content

Commit

Permalink
Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkin
Browse files Browse the repository at this point in the history
more clippy::complexity fixes

      redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
  • Loading branch information
workingjubilee authored Dec 13, 2023
2 parents df0686b + 3795cc8 commit 4583a01
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 28 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {

if !suggs.is_empty() {
err.multipart_suggestion_verbose(
format!("{msg}"),
msg,
suggs,
Applicability::MaybeIncorrect, // Issue #41966
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
span: Span,
) -> Result<PatKind<'tcx>, 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));
}

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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))
})
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(", "))),
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2245,8 +2245,8 @@ impl GenericArgs {
}
pub(crate) fn bindings<'a>(&'a self) -> Box<dyn Iterator<Item = TypeBinding> + '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 {
Expand All @@ -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))
}
}
Expand Down

0 comments on commit 4583a01

Please sign in to comment.