Skip to content

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

+1-2
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

+1-1
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

+1-2
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

+1-1
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

+2-2
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

+1-2
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

+1-1
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

+2-2
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

+2-2
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

+1-3
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 }

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
263263
}
264264

265265
// check that the value being matched on is the same. The
266-
if this_bb_discr_info.targets_with_values.iter().find(|x| x.0 == value).is_none() {
266+
if !this_bb_discr_info.targets_with_values.iter().any(|x| x.0 == value) {
267267
trace!("NO: values being matched on are not the same");
268268
return None;
269269
}

compiler/rustc_mir_transform/src/normalize_array_len.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl<'a, 'tcx> Patcher<'a, 'tcx> {
111111
Operand::Copy(place) | Operand::Move(place) => {
112112
// create new local
113113
let ty = operand.ty(self.local_decls, self.tcx);
114-
let local_decl =
115-
LocalDecl::with_source_info(ty, statement.source_info.clone());
114+
let local_decl = LocalDecl::with_source_info(ty, statement.source_info);
116115
let local = self.local_decls.push(local_decl);
117116
// make it live
118117
let mut make_live_statement = statement.clone();

compiler/rustc_passes/src/check_attr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1766,8 +1766,7 @@ impl CheckAttrVisitor<'tcx> {
17661766
fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
17671767
if target != Target::MacroDef {
17681768
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1769-
lint.build(&format!("`#[macro_export]` only has an effect on macro definitions"))
1770-
.emit();
1769+
lint.build("`#[macro_export]` only has an effect on macro definitions").emit();
17711770
});
17721771
}
17731772
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
278278

279279
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
280280
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
281-
if self.is_poly == false {
281+
if !self.is_poly {
282282
visit::walk_expr(self, expr)
283283
}
284284
}
285285

286286
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
287287
self.is_poly |= pat.ty.definitely_has_param_types_or_consts(self.tcx);
288-
if self.is_poly == false {
288+
if !self.is_poly {
289289
visit::walk_pat(self, pat);
290290
}
291291
}
@@ -298,7 +298,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
298298
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
299299
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
300300
debug!("AbstractConstBuilder: is_poly={}", is_poly_vis.is_poly);
301-
if is_poly_vis.is_poly == false {
301+
if !is_poly_vis.is_poly {
302302
return Ok(None);
303303
}
304304

compiler/rustc_traits/src/chalk/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
892892
match r {
893893
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
894894
ty::BoundRegionKind::BrNamed(def_id, _name) => {
895-
if self.named_parameters.iter().find(|d| **d == def_id).is_none() {
895+
if !self.named_parameters.iter().any(|d| *d == def_id) {
896896
self.named_parameters.push(def_id);
897897
}
898898
}

compiler/rustc_typeck/src/check/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
329329
let obligation = Obligation::new(
330330
ObligationCause::dummy_with_span(callee_expr.span),
331331
self.param_env,
332-
predicate.clone(),
332+
*predicate,
333333
);
334334
let result = self.infcx.evaluate_obligation(&obligation);
335335
self.tcx

compiler/rustc_typeck/src/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
413413
}
414414

415415
hir::ExprKind::Match(ref discr, arms, _) => {
416-
self.link_match(discr, &arms[..]);
416+
self.link_match(discr, arms);
417417

418418
intravisit::walk_expr(self, expr);
419419
}

src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
207207
debug!("Done with crate");
208208

209209
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
210-
self.get_impls(primitive.clone());
210+
self.get_impls(*primitive);
211211
}
212212

213213
let mut index = (*self.index).clone().into_inner();

0 commit comments

Comments
 (0)