diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 18:00:27 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 18:01:01 +0100 |
commit | bccf77f26cd504de14f7d7d03f9f2a85d0fabb3d (patch) | |
tree | 2d38ea6fb04b05a44467bd9614253b8621848f20 /crates/hir/src/diagnostics.rs | |
parent | 886b66cd03cbe7cb13e248d7c7bbdeba66c7796a (diff) |
internal: refactor missing unsafe diagnostic
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 22 |
1 files changed, 2 insertions, 20 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)] |
111 | pub struct MissingUnsafe { | 109 | pub struct MissingUnsafe { |
112 | pub file: HirFileId, | 110 | pub expr: InFile<AstPtr<ast::Expr>>, |
113 | pub expr: AstPtr<ast::Expr>, | ||
114 | } | ||
115 | |||
116 | impl 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)] |