aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/expr.rs
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-05-27 13:51:08 +0100
committerPaul Daniel Faria <[email protected]>2020-06-27 15:10:26 +0100
commit9ce44be2ab7e9a99eece1c2e254f15ad1c6d73c5 (patch)
tree904c2c860ff62242bb01af23ea662c70cbe1152f /crates/ra_hir_ty/src/expr.rs
parentb9569886a915f2411adaecbcad28eda8b163c3e3 (diff)
Address review comments, have MissingUnsafe diagnostic point to each unsafe use, update tests
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/expr.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index ce73251b8..5f332aadb 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -2,9 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{path::path, resolver::HasResolver, AdtId, DefWithBodyId, FunctionId};
6 path::path, resolver::HasResolver, src::HasSource, AdtId, DefWithBodyId, FunctionId, Lookup,
7};
8use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
9use ra_syntax::{ast, AstPtr}; 7use ra_syntax::{ast, AstPtr};
10use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
@@ -346,7 +344,7 @@ pub fn unsafe_expressions(
346 } 344 }
347 } 345 }
348 Expr::Call { callee, .. } => { 346 Expr::Call { callee, .. } => {
349 let ty = &infer.type_of_expr[*callee]; 347 let ty = &infer[*callee];
350 if let &Ty::Apply(ApplicationTy { 348 if let &Ty::Apply(ApplicationTy {
351 ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)), 349 ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)),
352 .. 350 ..
@@ -361,7 +359,7 @@ pub fn unsafe_expressions(
361 if infer 359 if infer
362 .method_resolution(id) 360 .method_resolution(id)
363 .map(|func| db.function_data(func).is_unsafe) 361 .map(|func| db.function_data(func).is_unsafe)
364 .unwrap_or_else(|| false) 362 .unwrap_or(false)
365 { 363 {
366 unsafe_exprs.push(UnsafeExpr::new(id)); 364 unsafe_exprs.push(UnsafeExpr::new(id));
367 } 365 }
@@ -409,7 +407,7 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> {
409 let func_data = db.function_data(self.func); 407 let func_data = db.function_data(self.func);
410 if func_data.is_unsafe 408 if func_data.is_unsafe
411 || unsafe_expressions 409 || unsafe_expressions
412 .into_iter() 410 .iter()
413 .filter(|unsafe_expr| !unsafe_expr.inside_unsafe_block) 411 .filter(|unsafe_expr| !unsafe_expr.inside_unsafe_block)
414 .count() 412 .count()
415 == 0 413 == 0
@@ -417,12 +415,11 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> {
417 return; 415 return;
418 } 416 }
419 417
420 let loc = self.func.lookup(db.upcast()); 418 let (_, body_source) = db.body_with_source_map(def);
421 let in_file = loc.source(db.upcast()); 419 for unsafe_expr in unsafe_expressions {
422 420 if let Ok(in_file) = body_source.as_ref().expr_syntax(unsafe_expr.expr) {
423 let file = in_file.file_id; 421 self.sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value })
424 let fn_def = AstPtr::new(&in_file.value); 422 }
425 423 }
426 self.sink.push(MissingUnsafe { file, fn_def })
427 } 424 }
428} 425}