aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 17:45:16 +0100
committerAleksey Kladov <[email protected]>2021-06-13 17:45:16 +0100
commit7166e8549bad95b05f66acd508d07a6cd97d3dc0 (patch)
treecf85d27f8eda6afdf4f9a92bcf646a7e1ce77397 /crates/hir
parentd3621eeb02652038a8185f60d78fb4791a732dc6 (diff)
internal: refactor NoSuchField diagnostic
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/diagnostics.rs25
-rw-r--r--crates/hir/src/lib.rs2
2 files changed, 3 insertions, 24 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 3908e67a2..c7702e09f 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -35,6 +35,7 @@ diagnostics![
35 InactiveCode, 35 InactiveCode,
36 MacroError, 36 MacroError,
37 MissingFields, 37 MissingFields,
38 NoSuchField,
38 UnimplementedBuiltinMacro, 39 UnimplementedBuiltinMacro,
39 UnresolvedExternCrate, 40 UnresolvedExternCrate,
40 UnresolvedImport, 41 UnresolvedImport,
@@ -92,31 +93,9 @@ pub struct UnimplementedBuiltinMacro {
92 pub node: InFile<SyntaxNodePtr>, 93 pub node: InFile<SyntaxNodePtr>,
93} 94}
94 95
95// Diagnostic: no-such-field
96//
97// This diagnostic is triggered if created structure does not have field provided in record.
98#[derive(Debug)] 96#[derive(Debug)]
99pub struct NoSuchField { 97pub struct NoSuchField {
100 pub file: HirFileId, 98 pub field: InFile<AstPtr<ast::RecordExprField>>,
101 pub field: AstPtr<ast::RecordExprField>,
102}
103
104impl Diagnostic for NoSuchField {
105 fn code(&self) -> DiagnosticCode {
106 DiagnosticCode("no-such-field")
107 }
108
109 fn message(&self) -> String {
110 "no such field".to_string()
111 }
112
113 fn display_source(&self) -> InFile<SyntaxNodePtr> {
114 InFile::new(self.file, self.field.clone().into())
115 }
116
117 fn as_any(&self) -> &(dyn Any + Send + 'static) {
118 self
119 }
120} 99}
121 100
122// Diagnostic: break-outside-of-loop 101// Diagnostic: break-outside-of-loop
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index a361158e0..7faf6ec1f 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1077,7 +1077,7 @@ impl Function {
1077 match d { 1077 match d {
1078 hir_ty::InferenceDiagnostic::NoSuchField { expr } => { 1078 hir_ty::InferenceDiagnostic::NoSuchField { expr } => {
1079 let field = source_map.field_syntax(*expr); 1079 let field = source_map.field_syntax(*expr);
1080 sink.push(NoSuchField { file: field.file_id, field: field.value }) 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 ptr = source_map