mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
internal: move missing unsafe diagnostic to hir
This commit is contained in:
parent
f8009666be
commit
0413d51317
6 changed files with 145 additions and 166 deletions
|
@ -17,7 +17,10 @@ use crate::{
|
|||
diagnostics_sink::{Diagnostic, DiagnosticCode, DiagnosticSink},
|
||||
};
|
||||
|
||||
pub use crate::diagnostics::expr::{record_literal_missing_fields, record_pattern_missing_fields};
|
||||
pub use crate::diagnostics::{
|
||||
expr::{record_literal_missing_fields, record_pattern_missing_fields},
|
||||
unsafe_check::missing_unsafe,
|
||||
};
|
||||
|
||||
pub fn validate_module_item(
|
||||
db: &dyn HirDatabase,
|
||||
|
@ -35,8 +38,6 @@ pub fn validate_body(db: &dyn HirDatabase, owner: DefWithBodyId, sink: &mut Diag
|
|||
let infer = db.infer(owner);
|
||||
let mut validator = expr::ExprValidator::new(owner, infer.clone(), sink);
|
||||
validator.validate_body(db);
|
||||
let mut validator = unsafe_check::UnsafeValidator::new(owner, infer, sink);
|
||||
validator.validate_body(db);
|
||||
}
|
||||
|
||||
// Diagnostic: missing-structure-fields
|
||||
|
@ -219,30 +220,6 @@ impl Diagnostic for RemoveThisSemicolon {
|
|||
}
|
||||
}
|
||||
|
||||
// Diagnostic: missing-unsafe
|
||||
//
|
||||
// This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block.
|
||||
#[derive(Debug)]
|
||||
pub struct MissingUnsafe {
|
||||
pub file: HirFileId,
|
||||
pub expr: AstPtr<ast::Expr>,
|
||||
}
|
||||
|
||||
impl Diagnostic for MissingUnsafe {
|
||||
fn code(&self) -> DiagnosticCode {
|
||||
DiagnosticCode("missing-unsafe")
|
||||
}
|
||||
fn message(&self) -> String {
|
||||
format!("This operation is unsafe and requires an unsafe function or block")
|
||||
}
|
||||
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.expr.clone().into() }
|
||||
}
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// Diagnostic: mismatched-arg-count
|
||||
//
|
||||
// This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue