aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/expr.rs29
1 files changed, 10 insertions, 19 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 04668f486..1a0710e0b 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -13,8 +13,8 @@ use crate::{
13 db::HirDatabase, 13 db::HirDatabase,
14 diagnostics::{ 14 diagnostics::{
15 MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields, MissingUnsafe, 15 MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields, MissingUnsafe,
16 UnnecessaryUnsafe,
17 }, 16 },
17 lower::CallableDef,
18 utils::variant_data, 18 utils::variant_data,
19 ApplicationTy, InferenceResult, Ty, TypeCtor, 19 ApplicationTy, InferenceResult, Ty, TypeCtor,
20 _match::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness}, 20 _match::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness},
@@ -328,17 +328,14 @@ pub fn unsafe_expressions(
328 for (id, expr) in body.exprs.iter() { 328 for (id, expr) in body.exprs.iter() {
329 match expr { 329 match expr {
330 Expr::Call { callee, .. } => { 330 Expr::Call { callee, .. } => {
331 if infer 331 let ty = &infer.type_of_expr[*callee];
332 .method_resolution(/* id */ *callee) 332 if let &Ty::Apply(ApplicationTy {ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)), .. }) = ty {
333 .map(|func| db.function_data(func).is_unsafe) 333 if db.function_data(func).is_unsafe {
334 .unwrap_or(false) 334 unsafe_expr_ids.push(id);
335 { 335 }
336 unsafe_expr_ids.push(id); 336 }
337 }
338 } 337 }
339 Expr::MethodCall {/*_receiver, method_name,*/ .. } => { 338 Expr::MethodCall { .. } => {
340 // let receiver_ty = &infer.type_of_expr[*receiver];
341 // receiver_ty
342 if infer 339 if infer
343 .method_resolution(id) 340 .method_resolution(id)
344 .map(|func| { 341 .map(|func| {
@@ -382,9 +379,7 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> {
382 let def = self.func.into(); 379 let def = self.func.into();
383 let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def); 380 let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def);
384 let func_data = db.function_data(self.func); 381 let func_data = db.function_data(self.func);
385 let unnecessary = func_data.is_unsafe && unsafe_expressions.len() == 0; 382 if func_data.is_unsafe || unsafe_expressions.len() == 0 {
386 let missing = !func_data.is_unsafe && unsafe_expressions.len() > 0;
387 if !(unnecessary || missing) {
388 return; 383 return;
389 } 384 }
390 385
@@ -394,10 +389,6 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> {
394 let file = in_file.file_id; 389 let file = in_file.file_id;
395 let fn_def = AstPtr::new(&in_file.value); 390 let fn_def = AstPtr::new(&in_file.value);
396 391
397 if unnecessary { 392 self.sink.push(MissingUnsafe { file, fn_def })
398 self.sink.push(UnnecessaryUnsafe { file, fn_def })
399 } else {
400 self.sink.push(MissingUnsafe { file, fn_def })
401 }
402 } 393 }
403} 394}