提交 e6f77a17 编写于 作者: M Matthias Krüger

clippy::complexity fixes

上级 0157cc97
......@@ -1345,8 +1345,7 @@ pub(super) fn lower_generics_mut(
generics
.params
.iter()
.find(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
.is_some()
.any(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
}
// Either the `bounded_ty` is not a plain type parameter, or
// it's not found in the generic type parameters list.
......
......@@ -201,7 +201,7 @@ fn precompute_borrows_out_of_scope(
let bb_data = &self.body[bb];
debug_assert!(hi == bb_data.statements.len());
for &succ_bb in bb_data.terminator().successors() {
if self.visited.insert(succ_bb) == false {
if !self.visited.insert(succ_bb) {
if succ_bb == location.block && first_lo > 0 {
// `succ_bb` has been seen before. If it wasn't
// fully processed, add its first part to `stack`
......
......@@ -972,8 +972,7 @@ fn suggest_ampmut<'tcx>(
if let Some(assignment_rhs_span) = opt_assignment_rhs_span {
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) {
let is_mutbl = |ty: &str| -> bool {
if ty.starts_with("mut") {
let rest = &ty[3..];
if let Some(rest) = ty.strip_prefix("mut") {
match rest.chars().next() {
// e.g. `&mut x`
Some(c) if c.is_whitespace() => true,
......
......@@ -594,7 +594,7 @@ fn create_derived_impl(
GenericParamKind::Const { ty, kw_span, .. } => {
let const_nodefault_kind = GenericParamKind::Const {
ty: ty.clone(),
kw_span: kw_span.clone(),
kw_span: *kw_span,
// We can't have default values inside impl block
default: None,
......
......@@ -130,8 +130,8 @@ fn emit_associated_type_err(
.tcx()
.sess
.struct_span_err(span, &format!("`impl` associated type signature for `{}` doesn't match `trait` associated type signature", item_name));
err.span_label(impl_sp, &format!("found"));
err.span_label(trait_sp, &format!("expected"));
err.span_label(impl_sp, "found");
err.span_label(trait_sp, "expected");
err.emit();
}
......
......@@ -230,8 +230,7 @@ fn check_panic_str<'tcx>(
Err(_) => (None, None),
};
let mut fmt_parser =
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
let mut fmt_parser = Parser::new(fmt, style, snippet.clone(), false, ParseMode::Format);
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
if n_arguments > 0 && fmt_parser.errors.is_empty() {
......
......@@ -363,7 +363,7 @@ fn process_command_line(&mut self) {
.collect::<Vec<_>>();
if existing.is_empty() {
// Add if not found
let new_name = passed_lib.new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
let new_name: Option<&str> = passed_lib.new_name.as_deref();
let lib = NativeLib {
name: Some(Symbol::intern(new_name.unwrap_or(&passed_lib.name))),
kind: passed_lib.kind,
......
......@@ -986,7 +986,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'
let niche = if def.repr.hide_niche() {
None
} else {
Niche::from_scalar(dl, Size::ZERO, scalar.clone())
Niche::from_scalar(dl, Size::ZERO, *scalar)
};
if let Some(niche) = niche {
match st.largest_niche {
......@@ -2273,7 +2273,7 @@ fn field_ty_or_layout(
) -> TyMaybeWithLayout<'tcx> {
let tcx = cx.tcx();
let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> {
let layout = Layout::scalar(cx, tag.clone());
let layout = Layout::scalar(cx, tag);
TyAndLayout { layout: tcx.intern_layout(layout), ty: tag.value.to_ty(tcx) }
};
......
......@@ -130,7 +130,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
TerminatorKind::Call {
func: exchange_malloc,
args: vec![Operand::Move(size), Operand::Move(align)],
destination: Some((Place::from(storage), success)),
destination: Some((storage, success)),
cleanup: None,
from_hir_call: false,
fn_span: expr_span,
......@@ -153,7 +153,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
// Transmute `*mut u8` to the box (thus far, uninitialized):
let box_ = Rvalue::ShallowInitBox(Operand::Move(Place::from(storage)), value.ty);
let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value.ty);
this.cfg.push_assign(block, source_info, Place::from(result), box_);
// initialize the box contents:
......
......@@ -1068,9 +1068,7 @@ pub(super) fn iter_missing<'a, 'p>(
Missing {
nonexhaustive_enum_missing_real_variants: self
.iter_missing(pcx)
.filter(|c| !c.is_non_exhaustive())
.next()
.is_some(),
.any(|c| !c.is_non_exhaustive()),
}
} else {
Missing { nonexhaustive_enum_missing_real_variants: false }
......
......@@ -263,7 +263,7 @@ fn find_discriminant_switch_pairing(
}
// check that the value being matched on is the same. The
if this_bb_discr_info.targets_with_values.iter().find(|x| x.0 == value).is_none() {
if !this_bb_discr_info.targets_with_values.iter().any(|x| x.0 == value) {
trace!("NO: values being matched on are not the same");
return None;
}
......
......@@ -111,8 +111,7 @@ fn patch_expand_statement(
Operand::Copy(place) | Operand::Move(place) => {
// create new local
let ty = operand.ty(self.local_decls, self.tcx);
let local_decl =
LocalDecl::with_source_info(ty, statement.source_info.clone());
let local_decl = LocalDecl::with_source_info(ty, statement.source_info);
let local = self.local_decls.push(local_decl);
// make it live
let mut make_live_statement = statement.clone();
......
......@@ -1766,8 +1766,7 @@ fn check_macro_use(&self, hir_id: HirId, attr: &Attribute, target: Target) {
fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
if target != Target::MacroDef {
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build(&format!("`#[macro_export]` only has an effect on macro definitions"))
.emit();
lint.build("`#[macro_export]` only has an effect on macro definitions").emit();
});
}
}
......
......@@ -278,14 +278,14 @@ fn thir(&self) -> &'a thir::Thir<'tcx> {
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
if self.is_poly == false {
if !self.is_poly {
visit::walk_expr(self, expr)
}
}
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
self.is_poly |= pat.ty.definitely_has_param_types_or_consts(self.tcx);
if self.is_poly == false {
if !self.is_poly {
visit::walk_pat(self, pat);
}
}
......@@ -298,7 +298,7 @@ fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) {
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
debug!("AbstractConstBuilder: is_poly={}", is_poly_vis.is_poly);
if is_poly_vis.is_poly == false {
if !is_poly_vis.is_poly {
return Ok(None);
}
......
......@@ -892,7 +892,7 @@ fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
match r {
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
ty::BoundRegionKind::BrNamed(def_id, _name) => {
if self.named_parameters.iter().find(|d| **d == def_id).is_none() {
if !self.named_parameters.iter().any(|d| *d == def_id) {
self.named_parameters.push(def_id);
}
}
......
......@@ -329,7 +329,7 @@ fn confirm_builtin_call(
let obligation = Obligation::new(
ObligationCause::dummy_with_span(callee_expr.span),
self.param_env,
predicate.clone(),
*predicate,
);
let result = self.infcx.evaluate_obligation(&obligation);
self.tcx
......
......@@ -413,7 +413,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
}
hir::ExprKind::Match(ref discr, arms, _) => {
self.link_match(discr, &arms[..]);
self.link_match(discr, arms);
intravisit::walk_expr(self, expr);
}
......
......@@ -207,7 +207,7 @@ fn after_krate(&mut self) -> Result<(), Error> {
debug!("Done with crate");
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
self.get_impls(primitive.clone());
self.get_impls(*primitive);
}
let mut index = (*self.index).clone().into_inner();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册