internal: refactor missing unsafe diagnostic

This commit is contained in:
Aleksey Kladov 2021-06-13 20:00:27 +03:00
parent 886b66cd03
commit bccf77f26c
4 changed files with 106 additions and 107 deletions

View file

@ -36,6 +36,7 @@ diagnostics![
InactiveCode,
MacroError,
MissingFields,
MissingUnsafe,
NoSuchField,
UnimplementedBuiltinMacro,
UnresolvedExternCrate,
@ -104,28 +105,9 @@ pub struct BreakOutsideOfLoop {
pub expr: InFile<AstPtr<ast::Expr>>,
}
// 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
}
pub expr: InFile<AstPtr<ast::Expr>>,
}
#[derive(Debug)]