From eceaf94f1936436e33ae235ca65bf2a6d4f77da5 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 18 Feb 2020 15:32:19 +0200 Subject: More manual clippy fixes --- crates/ra_hir_ty/src/diagnostics.rs | 2 +- crates/ra_hir_ty/src/expr.rs | 2 +- crates/ra_hir_ty/src/infer/coerce.rs | 7 +++---- crates/ra_hir_ty/src/infer/expr.rs | 16 +++++----------- crates/ra_hir_ty/src/infer/unify.rs | 5 ++--- crates/ra_hir_ty/src/lib.rs | 5 ++--- crates/ra_hir_ty/src/op.rs | 24 +++++++++++------------- crates/ra_hir_ty/src/test_db.rs | 7 +++---- crates/ra_hir_ty/src/tests.rs | 8 ++++---- crates/ra_hir_ty/src/traits.rs | 9 +++------ crates/ra_hir_ty/src/traits/builtin.rs | 4 ++-- crates/ra_hir_ty/src/traits/chalk.rs | 3 +-- 12 files changed, 38 insertions(+), 54 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 5054189cc..6eafdc8f6 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -40,7 +40,7 @@ impl Diagnostic for MissingFields { use std::fmt::Write; let mut message = String::from("Missing structure fields:\n"); for field in &self.missed_fields { - write!(message, "- {}\n", field).unwrap(); + writeln!(message, "- {}", field).unwrap(); } message } diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index f752a9f09..0d11b537c 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -138,7 +138,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { _ => return, }; - if params.len() == 2 && ¶ms[0] == &mismatch.actual { + if params.len() == 2 && params[0] == mismatch.actual { let (_, source_map) = db.body_with_source_map(self.func.into()); if let Some(source_ptr) = source_map.expr_syntax(id) { diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 4a0eabdfc..fb6a51b12 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -26,7 +26,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { /// Note that it is only possible that one type are coerced to another. /// Coercing both types to another least upper bound type is not possible in rustc, /// which will simply result in "incompatible types" error. - pub(super) fn coerce_merge_branch<'t>(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { + pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { if self.coerce(ty1, ty2) { ty2.clone() } else if self.coerce(ty2, ty1) { @@ -252,15 +252,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let unsize_generic_index = { let mut index = None; let mut multiple_param = false; - field_tys[last_field_id].value.walk(&mut |ty| match ty { - &Ty::Bound(idx) => { + field_tys[last_field_id].value.walk(&mut |ty| { + if let &Ty::Bound(idx) = ty { if index.is_none() { index = Some(idx); } else if Some(idx) != index { multiple_param = true; } } - _ => {} }); if multiple_param { diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 0af94ae32..9d5f75625 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -35,8 +35,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, ); } - let ty = self.resolve_ty_as_possible(ty); - ty + self.resolve_ty_as_possible(ty) } /// Infer type of expression with possibly implicit coerce to the expected type. @@ -155,8 +154,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { }; self.register_obligations_for_call(&callee_ty); self.check_call_arguments(args, ¶m_tys); - let ret_ty = self.normalize_associated_types_in(ret_ty); - ret_ty + self.normalize_associated_types_in(ret_ty) } Expr::MethodCall { receiver, args, method_name, generic_args } => self .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), @@ -280,14 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Expr::Await { expr } => { let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); - let ty = - self.resolve_associated_type(inner_ty, self.resolve_future_future_output()); - ty + self.resolve_associated_type(inner_ty, self.resolve_future_future_output()) } Expr::Try { expr } => { let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); - let ty = self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok()); - ty + self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok()) } Expr::Cast { expr, type_ref } => { let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); @@ -611,8 +606,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.unify(&expected_receiver_ty, &actual_receiver_ty); self.check_call_arguments(args, ¶m_tys); - let ret_ty = self.normalize_associated_types_in(ret_ty); - ret_ty + self.normalize_associated_types_in(ret_ty) } fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index 1dc842f40..9c7996572 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs @@ -140,13 +140,12 @@ where impl Canonicalized { pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { ty.walk_mut_binders( - &mut |ty, binders| match ty { - &mut Ty::Bound(idx) => { + &mut |ty, binders| { + if let &mut Ty::Bound(idx) = ty { if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { *ty = Ty::Infer(self.free_vars[idx as usize - binders]); } } - _ => {} }, 0, ); diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 302bb8aa2..13c5e6c6b 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -763,8 +763,8 @@ pub trait TypeWalk { Self: Sized, { self.walk_mut_binders( - &mut |ty, binders| match ty { - &mut Ty::Bound(idx) => { + &mut |ty, binders| { + if let &mut Ty::Bound(idx) = ty { if idx as usize >= binders && (idx as usize - binders) < substs.len() { *ty = substs.0[idx as usize - binders].clone(); } else if idx as usize >= binders + substs.len() { @@ -772,7 +772,6 @@ pub trait TypeWalk { *ty = Ty::Bound(idx - substs.len() as u32); } } - _ => {} }, 0, ); diff --git a/crates/ra_hir_ty/src/op.rs b/crates/ra_hir_ty/src/op.rs index ae253ca04..54e2bd05a 100644 --- a/crates/ra_hir_ty/src/op.rs +++ b/crates/ra_hir_ty/src/op.rs @@ -30,20 +30,18 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { match op { BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), - BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => { - match lhs_ty { - Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { - TypeCtor::Int(..) - | TypeCtor::Float(..) - | TypeCtor::Str - | TypeCtor::Char - | TypeCtor::Bool => lhs_ty, - _ => Ty::Unknown, - }, - Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, + BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { + Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { + TypeCtor::Int(..) + | TypeCtor::Float(..) + | TypeCtor::Str + | TypeCtor::Char + | TypeCtor::Bool => lhs_ty, _ => Ty::Unknown, - } - } + }, + Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, + _ => Ty::Unknown, + }, BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, BinaryOp::CmpOp(CmpOp::Ord { .. }) | BinaryOp::Assignment { op: Some(_) } diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 1a31b587b..c794f7b84 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs @@ -86,15 +86,14 @@ impl TestDB { pub fn diagnostics(&self) -> String { let mut buf = String::new(); let crate_graph = self.crate_graph(); - for krate in crate_graph.iter().next() { + for krate in crate_graph.iter() { let crate_def_map = self.crate_def_map(krate); let mut fns = Vec::new(); for (module_id, _) in crate_def_map.modules.iter() { for decl in crate_def_map[module_id].scope.declarations() { - match decl { - ModuleDefId::FunctionId(f) => fns.push(f), - _ => (), + if let ModuleDefId::FunctionId(f) = decl { + fns.push(f) } } diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index d1f10e675..240cc03a2 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -101,9 +101,9 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) }; let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; - write!( + writeln!( acc, - "{}{} '{}': {}\n", + "{}{} '{}': {}", macro_prefix, range, ellipsize(text, 15), @@ -118,9 +118,9 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { for (src_ptr, mismatch) in &mismatches { let range = src_ptr.value.range(); let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; - write!( + writeln!( acc, - "{}{}: expected {}, got {}\n", + "{}{}: expected {}, got {}", macro_prefix, range, mismatch.expected.display(&db), diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index ff8e75b48..e83449957 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -248,12 +248,9 @@ fn solution_from_chalk( let value = subst .value .into_iter() - .map(|p| { - let ty = match p.ty() { - Some(ty) => from_chalk(db, ty.clone()), - None => unimplemented!(), - }; - ty + .map(|p| match p.ty() { + Some(ty) => from_chalk(db, ty.clone()), + None => unimplemented!(), }) .collect(); let result = Canonical { value, num_vars: subst.binders.len() }; diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 67120abf6..a537420a5 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -122,7 +122,7 @@ fn closure_fn_trait_impl_datum( substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), }; - let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()); + let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data); BuiltinImplData { num_vars: num_args as usize + 1, @@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value( krate: CrateId, data: super::ClosureFnTraitImplData, ) -> BuiltinImplAssocTyValueData { - let impl_ = Impl::ClosureFnTraitImpl(data.clone()); + let impl_ = Impl::ClosureFnTraitImpl(data); let num_args: u16 = match &db.body(data.def)[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 306909ec2..1bdf13e48 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -409,8 +409,7 @@ where fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical { let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); let value = self.value.to_chalk(db); - let canonical = chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }; - canonical + chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] } } fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical) -> Canonical { -- cgit v1.2.3