aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/diagnostics.rs22
-rw-r--r--crates/hir/src/lib.rs4
2 files changed, 3 insertions, 23 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 47d17ba70..f7bf63215 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -36,6 +36,7 @@ diagnostics![
36 InactiveCode, 36 InactiveCode,
37 MacroError, 37 MacroError,
38 MissingFields, 38 MissingFields,
39 MissingUnsafe,
39 NoSuchField, 40 NoSuchField,
40 UnimplementedBuiltinMacro, 41 UnimplementedBuiltinMacro,
41 UnresolvedExternCrate, 42 UnresolvedExternCrate,
@@ -104,28 +105,9 @@ pub struct BreakOutsideOfLoop {
104 pub expr: InFile<AstPtr<ast::Expr>>, 105 pub expr: InFile<AstPtr<ast::Expr>>,
105} 106}
106 107
107// Diagnostic: missing-unsafe
108//
109// This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block.
110#[derive(Debug)] 108#[derive(Debug)]
111pub struct MissingUnsafe { 109pub struct MissingUnsafe {
112 pub file: HirFileId, 110 pub expr: InFile<AstPtr<ast::Expr>>,
113 pub expr: AstPtr<ast::Expr>,
114}
115
116impl Diagnostic for MissingUnsafe {
117 fn code(&self) -> DiagnosticCode {
118 DiagnosticCode("missing-unsafe")
119 }
120 fn message(&self) -> String {
121 format!("This operation is unsafe and requires an unsafe function or block")
122 }
123 fn display_source(&self) -> InFile<SyntaxNodePtr> {
124 InFile { file_id: self.file, value: self.expr.clone().into() }
125 }
126 fn as_any(&self) -> &(dyn Any + Send + 'static) {
127 self
128 }
129} 111}
130 112
131#[derive(Debug)] 113#[derive(Debug)]
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 2f507b83b..16f862707 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1090,9 +1090,7 @@ impl Function {
1090 1090
1091 for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) { 1091 for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) {
1092 match source_map.expr_syntax(expr) { 1092 match source_map.expr_syntax(expr) {
1093 Ok(in_file) => { 1093 Ok(expr) => acc.push(MissingUnsafe { expr }.into()),
1094 sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value })
1095 }
1096 Err(SyntheticSyntax) => { 1094 Err(SyntheticSyntax) => {
1097 // FIXME: Here and eslwhere in this file, the `expr` was 1095 // FIXME: Here and eslwhere in this file, the `expr` was
1098 // desugared, report or assert that this doesn't happen. 1096 // desugared, report or assert that this doesn't happen.