diff options
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index b144bb335..9afee0b90 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -37,6 +37,7 @@ diagnostics![ | |||
37 | MacroError, | 37 | MacroError, |
38 | MismatchedArgCount, | 38 | MismatchedArgCount, |
39 | MissingFields, | 39 | MissingFields, |
40 | MissingOkOrSomeInTailExpr, | ||
40 | MissingUnsafe, | 41 | MissingUnsafe, |
41 | NoSuchField, | 42 | NoSuchField, |
42 | RemoveThisSemicolon, | 43 | RemoveThisSemicolon, |
@@ -157,41 +158,13 @@ pub struct RemoveThisSemicolon { | |||
157 | pub expr: InFile<AstPtr<ast::Expr>>, | 158 | pub expr: InFile<AstPtr<ast::Expr>>, |
158 | } | 159 | } |
159 | 160 | ||
160 | // Diagnostic: missing-ok-or-some-in-tail-expr | ||
161 | // | ||
162 | // This diagnostic is triggered if a block that should return `Result` returns a value not wrapped in `Ok`, | ||
163 | // or if a block that should return `Option` returns a value not wrapped in `Some`. | ||
164 | // | ||
165 | // Example: | ||
166 | // | ||
167 | // ```rust | ||
168 | // fn foo() -> Result<u8, ()> { | ||
169 | // 10 | ||
170 | // } | ||
171 | // ``` | ||
172 | #[derive(Debug)] | 161 | #[derive(Debug)] |
173 | pub struct MissingOkOrSomeInTailExpr { | 162 | pub struct MissingOkOrSomeInTailExpr { |
174 | pub file: HirFileId, | 163 | pub expr: InFile<AstPtr<ast::Expr>>, |
175 | pub expr: AstPtr<ast::Expr>, | ||
176 | // `Some` or `Ok` depending on whether the return type is Result or Option | 164 | // `Some` or `Ok` depending on whether the return type is Result or Option |
177 | pub required: String, | 165 | pub required: String, |
178 | } | 166 | } |
179 | 167 | ||
180 | impl Diagnostic for MissingOkOrSomeInTailExpr { | ||
181 | fn code(&self) -> DiagnosticCode { | ||
182 | DiagnosticCode("missing-ok-or-some-in-tail-expr") | ||
183 | } | ||
184 | fn message(&self) -> String { | ||
185 | format!("wrap return expression in {}", self.required) | ||
186 | } | ||
187 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
188 | InFile { file_id: self.file, value: self.expr.clone().into() } | ||
189 | } | ||
190 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
191 | self | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // Diagnostic: missing-match-arm | 168 | // Diagnostic: missing-match-arm |
196 | // | 169 | // |
197 | // This diagnostic is triggered if `match` block is missing one or more match arms. | 170 | // This diagnostic is triggered if `match` block is missing one or more match arms. |