diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 17:51:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 17:51:19 +0100 |
commit | 886b66cd03cbe7cb13e248d7c7bbdeba66c7796a (patch) | |
tree | 4479618bebc4f3b6bcc6159ad887cfc1591091b4 /crates/hir | |
parent | 7166e8549bad95b05f66acd508d07a6cd97d3dc0 (diff) |
internal: refactor BreakOutsideOfLoop diagnostic
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 22 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 4 |
2 files changed, 4 insertions, 22 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index c7702e09f..47d17ba70 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -32,6 +32,7 @@ macro_rules! diagnostics { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | diagnostics![ | 34 | diagnostics![ |
35 | BreakOutsideOfLoop, | ||
35 | InactiveCode, | 36 | InactiveCode, |
36 | MacroError, | 37 | MacroError, |
37 | MissingFields, | 38 | MissingFields, |
@@ -98,28 +99,9 @@ pub struct NoSuchField { | |||
98 | pub field: InFile<AstPtr<ast::RecordExprField>>, | 99 | pub field: InFile<AstPtr<ast::RecordExprField>>, |
99 | } | 100 | } |
100 | 101 | ||
101 | // Diagnostic: break-outside-of-loop | ||
102 | // | ||
103 | // This diagnostic is triggered if the `break` keyword is used outside of a loop. | ||
104 | #[derive(Debug)] | 102 | #[derive(Debug)] |
105 | pub struct BreakOutsideOfLoop { | 103 | pub struct BreakOutsideOfLoop { |
106 | pub file: HirFileId, | 104 | pub expr: InFile<AstPtr<ast::Expr>>, |
107 | pub expr: AstPtr<ast::Expr>, | ||
108 | } | ||
109 | |||
110 | impl Diagnostic for BreakOutsideOfLoop { | ||
111 | fn code(&self) -> DiagnosticCode { | ||
112 | DiagnosticCode("break-outside-of-loop") | ||
113 | } | ||
114 | fn message(&self) -> String { | ||
115 | "break outside of loop".to_string() | ||
116 | } | ||
117 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
118 | InFile { file_id: self.file, value: self.expr.clone().into() } | ||
119 | } | ||
120 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
121 | self | ||
122 | } | ||
123 | } | 105 | } |
124 | 106 | ||
125 | // Diagnostic: missing-unsafe | 107 | // Diagnostic: missing-unsafe |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 7faf6ec1f..2f507b83b 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -1080,10 +1080,10 @@ impl Function { | |||
1080 | acc.push(NoSuchField { field }.into()) | 1080 | acc.push(NoSuchField { field }.into()) |
1081 | } | 1081 | } |
1082 | hir_ty::InferenceDiagnostic::BreakOutsideOfLoop { expr } => { | 1082 | hir_ty::InferenceDiagnostic::BreakOutsideOfLoop { expr } => { |
1083 | let ptr = source_map | 1083 | let expr = source_map |
1084 | .expr_syntax(*expr) | 1084 | .expr_syntax(*expr) |
1085 | .expect("break outside of loop in synthetic syntax"); | 1085 | .expect("break outside of loop in synthetic syntax"); |
1086 | sink.push(BreakOutsideOfLoop { file: ptr.file_id, expr: ptr.value }) | 1086 | acc.push(BreakOutsideOfLoop { expr }.into()) |
1087 | } | 1087 | } |
1088 | } | 1088 | } |
1089 | } | 1089 | } |