From daf1cac9f87023d37a4418ea24ed615c9706258b Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Sun, 24 May 2020 01:33:22 -0400 Subject: Move diagnostics back into expr, add tests for diagnostics, fix logic to account for derefs of raw ptrs --- crates/ra_hir/src/code_model.rs | 5 ++-- crates/ra_hir/src/diagnostics.rs | 50 ---------------------------------------- 2 files changed, 2 insertions(+), 53 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 131180a63..13e763e52 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -25,7 +25,7 @@ use hir_expand::{ use hir_ty::{ autoderef, display::{HirDisplayError, HirFormatter}, - expr::ExprValidator, + expr::{ExprValidator, UnsafeValidator}, method_resolution, ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, }; @@ -36,7 +36,6 @@ use rustc_hash::FxHashSet; use crate::{ db::{DefDatabase, HirDatabase}, - diagnostics::UnsafeValidator, has_source::HasSource, CallableDef, HirDisplay, InFile, Name, }; @@ -680,7 +679,7 @@ impl Function { infer.add_diagnostics(db, self.id, sink); let mut validator = ExprValidator::new(self.id, infer.clone(), sink); validator.validate_body(db); - let mut validator = UnsafeValidator::new(&self, infer, sink); + let mut validator = UnsafeValidator::new(self.id, infer, sink); validator.validate_body(db); } } diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 562f3fe5c..c82883d0c 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs @@ -2,53 +2,3 @@ pub use hir_def::diagnostics::UnresolvedModule; pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; pub use hir_ty::diagnostics::{MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField}; - -use std::sync::Arc; - -use crate::code_model::Function; -use crate::db::HirDatabase; -use crate::has_source::HasSource; -use hir_ty::{ - diagnostics::{MissingUnsafe, UnnecessaryUnsafe}, - expr::unsafe_expressions, - InferenceResult, -}; -use ra_syntax::AstPtr; - -pub struct UnsafeValidator<'a, 'b: 'a> { - func: &'a Function, - infer: Arc, - sink: &'a mut DiagnosticSink<'b>, -} - -impl<'a, 'b> UnsafeValidator<'a, 'b> { - pub fn new( - func: &'a Function, - infer: Arc, - sink: &'a mut DiagnosticSink<'b>, - ) -> UnsafeValidator<'a, 'b> { - UnsafeValidator { func, infer, sink } - } - - pub fn validate_body(&mut self, db: &dyn HirDatabase) { - let def = self.func.id.into(); - let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def); - let func_data = db.function_data(self.func.id); - let unnecessary = func_data.is_unsafe && unsafe_expressions.len() == 0; - let missing = !func_data.is_unsafe && unsafe_expressions.len() > 0; - if !(unnecessary || missing) { - return; - } - - let in_file = self.func.source(db); - let file = in_file.file_id; - let fn_def = AstPtr::new(&in_file.value); - let fn_name = func_data.name.clone().into(); - - if unnecessary { - self.sink.push(UnnecessaryUnsafe { file, fn_def, fn_name }) - } else { - self.sink.push(MissingUnsafe { file, fn_def, fn_name }) - } - } -} -- cgit v1.2.3