diff options
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 48 |
1 files changed, 3 insertions, 45 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 3942aada5..99eed949f 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -9,9 +9,7 @@ use rustc_hash::FxHashSet; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::HirDatabase, | 11 | db::HirDatabase, |
12 | diagnostics::{ | 12 | diagnostics::{MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields}, |
13 | MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields, MissingUnsafe, | ||
14 | }, | ||
15 | lower::CallableDef, | 13 | lower::CallableDef, |
16 | utils::variant_data, | 14 | utils::variant_data, |
17 | ApplicationTy, InferenceResult, Ty, TypeCtor, | 15 | ApplicationTy, InferenceResult, Ty, TypeCtor, |
@@ -317,8 +315,8 @@ pub fn record_pattern_missing_fields( | |||
317 | } | 315 | } |
318 | 316 | ||
319 | pub struct UnsafeExpr { | 317 | pub struct UnsafeExpr { |
320 | expr: ExprId, | 318 | pub expr: ExprId, |
321 | inside_unsafe_block: bool, | 319 | pub inside_unsafe_block: bool, |
322 | } | 320 | } |
323 | 321 | ||
324 | impl UnsafeExpr { | 322 | impl UnsafeExpr { |
@@ -383,43 +381,3 @@ pub fn unsafe_expressions( | |||
383 | 381 | ||
384 | unsafe_exprs | 382 | unsafe_exprs |
385 | } | 383 | } |
386 | |||
387 | pub struct UnsafeValidator<'a, 'b: 'a> { | ||
388 | func: FunctionId, | ||
389 | infer: Arc<InferenceResult>, | ||
390 | sink: &'a mut DiagnosticSink<'b>, | ||
391 | } | ||
392 | |||
393 | impl<'a, 'b> UnsafeValidator<'a, 'b> { | ||
394 | pub fn new( | ||
395 | func: FunctionId, | ||
396 | infer: Arc<InferenceResult>, | ||
397 | sink: &'a mut DiagnosticSink<'b>, | ||
398 | ) -> UnsafeValidator<'a, 'b> { | ||
399 | UnsafeValidator { func, infer, sink } | ||
400 | } | ||
401 | |||
402 | pub fn validate_body(&mut self, db: &dyn HirDatabase) { | ||
403 | let def = self.func.into(); | ||
404 | let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def); | ||
405 | let func_data = db.function_data(self.func); | ||
406 | if func_data.is_unsafe | ||
407 | || unsafe_expressions | ||
408 | .iter() | ||
409 | .filter(|unsafe_expr| !unsafe_expr.inside_unsafe_block) | ||
410 | .count() | ||
411 | == 0 | ||
412 | { | ||
413 | return; | ||
414 | } | ||
415 | |||
416 | let (_, body_source) = db.body_with_source_map(def); | ||
417 | for unsafe_expr in unsafe_expressions { | ||
418 | if !unsafe_expr.inside_unsafe_block { | ||
419 | if let Ok(in_file) = body_source.as_ref().expr_syntax(unsafe_expr.expr) { | ||
420 | self.sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value }) | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | } | ||