aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-02-18 13:32:19 +0000
committerKirill Bulatov <[email protected]>2020-02-18 14:12:37 +0000
commiteceaf94f1936436e33ae235ca65bf2a6d4f77da5 (patch)
tree83d42e6f014f80b84f9193e6b5c7c1e2aded9fa7 /crates/ra_hir_ty/src
parentb8ddcb0652f3ec8683023afc1e1f5166d6a712f4 (diff)
More manual clippy fixes
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs2
-rw-r--r--crates/ra_hir_ty/src/expr.rs2
-rw-r--r--crates/ra_hir_ty/src/infer/coerce.rs7
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs16
-rw-r--r--crates/ra_hir_ty/src/infer/unify.rs5
-rw-r--r--crates/ra_hir_ty/src/lib.rs5
-rw-r--r--crates/ra_hir_ty/src/op.rs24
-rw-r--r--crates/ra_hir_ty/src/test_db.rs7
-rw-r--r--crates/ra_hir_ty/src/tests.rs8
-rw-r--r--crates/ra_hir_ty/src/traits.rs9
-rw-r--r--crates/ra_hir_ty/src/traits/builtin.rs4
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs3
12 files changed, 38 insertions, 54 deletions
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 {
40 use std::fmt::Write; 40 use std::fmt::Write;
41 let mut message = String::from("Missing structure fields:\n"); 41 let mut message = String::from("Missing structure fields:\n");
42 for field in &self.missed_fields { 42 for field in &self.missed_fields {
43 write!(message, "- {}\n", field).unwrap(); 43 writeln!(message, "- {}", field).unwrap();
44 } 44 }
45 message 45 message
46 } 46 }
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> {
138 _ => return, 138 _ => return,
139 }; 139 };
140 140
141 if params.len() == 2 && &params[0] == &mismatch.actual { 141 if params.len() == 2 && params[0] == mismatch.actual {
142 let (_, source_map) = db.body_with_source_map(self.func.into()); 142 let (_, source_map) = db.body_with_source_map(self.func.into());
143 143
144 if let Some(source_ptr) = source_map.expr_syntax(id) { 144 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> {
26 /// Note that it is only possible that one type are coerced to another. 26 /// Note that it is only possible that one type are coerced to another.
27 /// Coercing both types to another least upper bound type is not possible in rustc, 27 /// Coercing both types to another least upper bound type is not possible in rustc,
28 /// which will simply result in "incompatible types" error. 28 /// which will simply result in "incompatible types" error.
29 pub(super) fn coerce_merge_branch<'t>(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { 29 pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty {
30 if self.coerce(ty1, ty2) { 30 if self.coerce(ty1, ty2) {
31 ty2.clone() 31 ty2.clone()
32 } else if self.coerce(ty2, ty1) { 32 } else if self.coerce(ty2, ty1) {
@@ -252,15 +252,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
252 let unsize_generic_index = { 252 let unsize_generic_index = {
253 let mut index = None; 253 let mut index = None;
254 let mut multiple_param = false; 254 let mut multiple_param = false;
255 field_tys[last_field_id].value.walk(&mut |ty| match ty { 255 field_tys[last_field_id].value.walk(&mut |ty| {
256 &Ty::Bound(idx) => { 256 if let &Ty::Bound(idx) = ty {
257 if index.is_none() { 257 if index.is_none() {
258 index = Some(idx); 258 index = Some(idx);
259 } else if Some(idx) != index { 259 } else if Some(idx) != index {
260 multiple_param = true; 260 multiple_param = true;
261 } 261 }
262 } 262 }
263 _ => {}
264 }); 263 });
265 264
266 if multiple_param { 265 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> {
35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, 35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() },
36 ); 36 );
37 } 37 }
38 let ty = self.resolve_ty_as_possible(ty); 38 self.resolve_ty_as_possible(ty)
39 ty
40 } 39 }
41 40
42 /// Infer type of expression with possibly implicit coerce to the expected type. 41 /// Infer type of expression with possibly implicit coerce to the expected type.
@@ -155,8 +154,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
155 }; 154 };
156 self.register_obligations_for_call(&callee_ty); 155 self.register_obligations_for_call(&callee_ty);
157 self.check_call_arguments(args, &param_tys); 156 self.check_call_arguments(args, &param_tys);
158 let ret_ty = self.normalize_associated_types_in(ret_ty); 157 self.normalize_associated_types_in(ret_ty)
159 ret_ty
160 } 158 }
161 Expr::MethodCall { receiver, args, method_name, generic_args } => self 159 Expr::MethodCall { receiver, args, method_name, generic_args } => self
162 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), 160 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()),
@@ -280,14 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
280 } 278 }
281 Expr::Await { expr } => { 279 Expr::Await { expr } => {
282 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 280 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
283 let ty = 281 self.resolve_associated_type(inner_ty, self.resolve_future_future_output())
284 self.resolve_associated_type(inner_ty, self.resolve_future_future_output());
285 ty
286 } 282 }
287 Expr::Try { expr } => { 283 Expr::Try { expr } => {
288 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 284 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
289 let ty = self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok()); 285 self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok())
290 ty
291 } 286 }
292 Expr::Cast { expr, type_ref } => { 287 Expr::Cast { expr, type_ref } => {
293 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 288 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
@@ -611,8 +606,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
611 self.unify(&expected_receiver_ty, &actual_receiver_ty); 606 self.unify(&expected_receiver_ty, &actual_receiver_ty);
612 607
613 self.check_call_arguments(args, &param_tys); 608 self.check_call_arguments(args, &param_tys);
614 let ret_ty = self.normalize_associated_types_in(ret_ty); 609 self.normalize_associated_types_in(ret_ty)
615 ret_ty
616 } 610 }
617 611
618 fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { 612 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
140impl<T> Canonicalized<T> { 140impl<T> Canonicalized<T> {
141 pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { 141 pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty {
142 ty.walk_mut_binders( 142 ty.walk_mut_binders(
143 &mut |ty, binders| match ty { 143 &mut |ty, binders| {
144 &mut Ty::Bound(idx) => { 144 if let &mut Ty::Bound(idx) = ty {
145 if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { 145 if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() {
146 *ty = Ty::Infer(self.free_vars[idx as usize - binders]); 146 *ty = Ty::Infer(self.free_vars[idx as usize - binders]);
147 } 147 }
148 } 148 }
149 _ => {}
150 }, 149 },
151 0, 150 0,
152 ); 151 );
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 {
763 Self: Sized, 763 Self: Sized,
764 { 764 {
765 self.walk_mut_binders( 765 self.walk_mut_binders(
766 &mut |ty, binders| match ty { 766 &mut |ty, binders| {
767 &mut Ty::Bound(idx) => { 767 if let &mut Ty::Bound(idx) = ty {
768 if idx as usize >= binders && (idx as usize - binders) < substs.len() { 768 if idx as usize >= binders && (idx as usize - binders) < substs.len() {
769 *ty = substs.0[idx as usize - binders].clone(); 769 *ty = substs.0[idx as usize - binders].clone();
770 } else if idx as usize >= binders + substs.len() { 770 } else if idx as usize >= binders + substs.len() {
@@ -772,7 +772,6 @@ pub trait TypeWalk {
772 *ty = Ty::Bound(idx - substs.len() as u32); 772 *ty = Ty::Bound(idx - substs.len() as u32);
773 } 773 }
774 } 774 }
775 _ => {}
776 }, 775 },
777 0, 776 0,
778 ); 777 );
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 {
30pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { 30pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
31 match op { 31 match op {
32 BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), 32 BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool),
33 BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => { 33 BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty {
34 match lhs_ty { 34 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
35 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 35 TypeCtor::Int(..)
36 TypeCtor::Int(..) 36 | TypeCtor::Float(..)
37 | TypeCtor::Float(..) 37 | TypeCtor::Str
38 | TypeCtor::Str 38 | TypeCtor::Char
39 | TypeCtor::Char 39 | TypeCtor::Bool => lhs_ty,
40 | TypeCtor::Bool => lhs_ty,
41 _ => Ty::Unknown,
42 },
43 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
44 _ => Ty::Unknown, 40 _ => Ty::Unknown,
45 } 41 },
46 } 42 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
43 _ => Ty::Unknown,
44 },
47 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, 45 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown,
48 BinaryOp::CmpOp(CmpOp::Ord { .. }) 46 BinaryOp::CmpOp(CmpOp::Ord { .. })
49 | BinaryOp::Assignment { op: Some(_) } 47 | 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 {
86 pub fn diagnostics(&self) -> String { 86 pub fn diagnostics(&self) -> String {
87 let mut buf = String::new(); 87 let mut buf = String::new();
88 let crate_graph = self.crate_graph(); 88 let crate_graph = self.crate_graph();
89 for krate in crate_graph.iter().next() { 89 for krate in crate_graph.iter() {
90 let crate_def_map = self.crate_def_map(krate); 90 let crate_def_map = self.crate_def_map(krate);
91 91
92 let mut fns = Vec::new(); 92 let mut fns = Vec::new();
93 for (module_id, _) in crate_def_map.modules.iter() { 93 for (module_id, _) in crate_def_map.modules.iter() {
94 for decl in crate_def_map[module_id].scope.declarations() { 94 for decl in crate_def_map[module_id].scope.declarations() {
95 match decl { 95 if let ModuleDefId::FunctionId(f) = decl {
96 ModuleDefId::FunctionId(f) => fns.push(f), 96 fns.push(f)
97 _ => (),
98 } 97 }
99 } 98 }
100 99
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 {
101 (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) 101 (src_ptr.value.range(), node.text().to_string().replace("\n", " "))
102 }; 102 };
103 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; 103 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" };
104 write!( 104 writeln!(
105 acc, 105 acc,
106 "{}{} '{}': {}\n", 106 "{}{} '{}': {}",
107 macro_prefix, 107 macro_prefix,
108 range, 108 range,
109 ellipsize(text, 15), 109 ellipsize(text, 15),
@@ -118,9 +118,9 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
118 for (src_ptr, mismatch) in &mismatches { 118 for (src_ptr, mismatch) in &mismatches {
119 let range = src_ptr.value.range(); 119 let range = src_ptr.value.range();
120 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; 120 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" };
121 write!( 121 writeln!(
122 acc, 122 acc,
123 "{}{}: expected {}, got {}\n", 123 "{}{}: expected {}, got {}",
124 macro_prefix, 124 macro_prefix,
125 range, 125 range,
126 mismatch.expected.display(&db), 126 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(
248 let value = subst 248 let value = subst
249 .value 249 .value
250 .into_iter() 250 .into_iter()
251 .map(|p| { 251 .map(|p| match p.ty() {
252 let ty = match p.ty() { 252 Some(ty) => from_chalk(db, ty.clone()),
253 Some(ty) => from_chalk(db, ty.clone()), 253 None => unimplemented!(),
254 None => unimplemented!(),
255 };
256 ty
257 }) 254 })
258 .collect(); 255 .collect();
259 let result = Canonical { value, num_vars: subst.binders.len() }; 256 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(
122 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), 122 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
123 }; 123 };
124 124
125 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()); 125 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data);
126 126
127 BuiltinImplData { 127 BuiltinImplData {
128 num_vars: num_args as usize + 1, 128 num_vars: num_args as usize + 1,
@@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value(
137 krate: CrateId, 137 krate: CrateId,
138 data: super::ClosureFnTraitImplData, 138 data: super::ClosureFnTraitImplData,
139) -> BuiltinImplAssocTyValueData { 139) -> BuiltinImplAssocTyValueData {
140 let impl_ = Impl::ClosureFnTraitImpl(data.clone()); 140 let impl_ = Impl::ClosureFnTraitImpl(data);
141 141
142 let num_args: u16 = match &db.body(data.def)[data.expr] { 142 let num_args: u16 = match &db.body(data.def)[data.expr] {
143 Expr::Lambda { args, .. } => args.len() as u16, 143 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
409 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> { 409 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> {
410 let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); 410 let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT);
411 let value = self.value.to_chalk(db); 411 let value = self.value.to_chalk(db);
412 let canonical = chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }; 412 chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }
413 canonical
414 } 413 }
415 414
416 fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { 415 fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {