diff options
author | Paul Daniel Faria <[email protected]> | 2020-05-24 18:18:31 +0100 |
---|---|---|
committer | Paul Daniel Faria <[email protected]> | 2020-06-27 15:09:42 +0100 |
commit | 499d4c454d1a66d10c3cf4c9bacbdb15f295af39 (patch) | |
tree | 867d1823b0533d2f198254c660cc03327651b57c /crates/ra_hir_ty/src/expr.rs | |
parent | b358fbfdf82409700a8a328794429ec790306fc2 (diff) |
Remove UnnecessaryUnsafe diagnostic, Fix Expr::Call unsafe analysis
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 29 |
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 | } |