Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e6f77a1

Browse files
committed
clippy::complexity fixes
1 parent 0157cc9 commit e6f77a1

File tree

18 files changed

+23
-30
lines changed

18 files changed

+23
-30
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13451345
generics
13461346
.params
13471347
.iter()
1348-
.find(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
1349-
.is_some()
1348+
.any(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
13501349
}
13511350
// Either the `bounded_ty` is not a plain type parameter, or
13521351
// it's not found in the generic type parameters list.

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
201201
let bb_data = &self.body[bb];
202202
debug_assert!(hi == bb_data.statements.len());
203203
for &succ_bb in bb_data.terminator().successors() {
204-
if self.visited.insert(succ_bb) == false {
204+
if !self.visited.insert(succ_bb) {
205205
if succ_bb == location.block && first_lo > 0 {
206206
// `succ_bb` has been seen before. If it wasn't
207207
// fully processed, add its first part to `stack`

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ fn suggest_ampmut<'tcx>(
972972
if let Some(assignment_rhs_span) = opt_assignment_rhs_span {
973973
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) {
974974
let is_mutbl = |ty: &str| -> bool {
975-
if ty.starts_with("mut") {
976-
let rest = &ty[3..];
975+
if let Some(rest) = ty.strip_prefix("mut") {
977976
match rest.chars().next() {
978977
// e.g. `&mut x`
979978
Some(c) if c.is_whitespace() => true,

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<'a> TraitDef<'a> {
594594
GenericParamKind::Const { ty, kw_span, .. } => {
595595
let const_nodefault_kind = GenericParamKind::Const {
596596
ty: ty.clone(),
597-
kw_span: kw_span.clone(),
597+
kw_span: *kw_span,
598598

599599
// We can't have default values inside impl block
600600
default: None,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
130130
.tcx()
131131
.sess
132132
.struct_span_err(span, &format!("`impl` associated type signature for `{}` doesn't match `trait` associated type signature", item_name));
133-
err.span_label(impl_sp, &format!("found"));
134-
err.span_label(trait_sp, &format!("expected"));
133+
err.span_label(impl_sp, "found");
134+
err.span_label(trait_sp, "expected");
135135

136136
err.emit();
137137
}

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ fn check_panic_str<'tcx>(
230230
Err(_) => (None, None),
231231
};
232232

233-
let mut fmt_parser =
234-
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
233+
let mut fmt_parser = Parser::new(fmt, style, snippet.clone(), false, ParseMode::Format);
235234
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
236235

237236
if n_arguments > 0 && fmt_parser.errors.is_empty() {

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Collector<'tcx> {
363363
.collect::<Vec<_>>();
364364
if existing.is_empty() {
365365
// Add if not found
366-
let new_name = passed_lib.new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
366+
let new_name: Option<&str> = passed_lib.new_name.as_deref();
367367
let lib = NativeLib {
368368
name: Some(Symbol::intern(new_name.unwrap_or(&passed_lib.name))),
369369
kind: passed_lib.kind,

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
986986
let niche = if def.repr.hide_niche() {
987987
None
988988
} else {
989-
Niche::from_scalar(dl, Size::ZERO, scalar.clone())
989+
Niche::from_scalar(dl, Size::ZERO, *scalar)
990990
};
991991
if let Some(niche) = niche {
992992
match st.largest_niche {
@@ -2273,7 +2273,7 @@ where
22732273
) -> TyMaybeWithLayout<'tcx> {
22742274
let tcx = cx.tcx();
22752275
let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> {
2276-
let layout = Layout::scalar(cx, tag.clone());
2276+
let layout = Layout::scalar(cx, tag);
22772277
TyAndLayout { layout: tcx.intern_layout(layout), ty: tag.value.to_ty(tcx) }
22782278
};
22792279

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
130130
TerminatorKind::Call {
131131
func: exchange_malloc,
132132
args: vec![Operand::Move(size), Operand::Move(align)],
133-
destination: Some((Place::from(storage), success)),
133+
destination: Some((storage, success)),
134134
cleanup: None,
135135
from_hir_call: false,
136136
fn_span: expr_span,
@@ -153,7 +153,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
153153
}
154154

155155
// Transmute `*mut u8` to the box (thus far, uninitialized):
156-
let box_ = Rvalue::ShallowInitBox(Operand::Move(Place::from(storage)), value.ty);
156+
let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value.ty);
157157
this.cfg.push_assign(block, source_info, Place::from(result), box_);
158158

159159
// initialize the box contents:

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,7 @@ impl<'tcx> SplitWildcard<'tcx> {
10681068
Missing {
10691069
nonexhaustive_enum_missing_real_variants: self
10701070
.iter_missing(pcx)
1071-
.filter(|c| !c.is_non_exhaustive())
1072-
.next()
1073-
.is_some(),
1071+
.any(|c| !c.is_non_exhaustive()),
10741072
}
10751073
} else {
10761074
Missing { nonexhaustive_enum_missing_real_variants: false }

0 commit comments

Comments
 (0)