aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs50
-rw-r--r--crates/ra_hir_ty/src/diagnostics/expr.rs5
-rw-r--r--crates/ra_hir_ty/src/diagnostics/match_check.rs8
3 files changed, 19 insertions, 44 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index a4cede81d..48b578fb0 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -59,8 +59,8 @@ impl AstDiagnostic for NoSuchField {
59pub struct MissingFields { 59pub struct MissingFields {
60 pub file: HirFileId, 60 pub file: HirFileId,
61 pub field_list: AstPtr<ast::RecordExprFieldList>, 61 pub field_list: AstPtr<ast::RecordExprFieldList>,
62 pub field_list_parent_path: Option<AstPtr<ast::Path>>,
62 pub missed_fields: Vec<Name>, 63 pub missed_fields: Vec<Name>,
63 pub list_parent_path: Option<AstPtr<ast::Path>>,
64} 64}
65 65
66impl Diagnostic for MissingFields { 66impl Diagnostic for MissingFields {
@@ -76,7 +76,7 @@ impl Diagnostic for MissingFields {
76 } 76 }
77 77
78 fn source(&self) -> InFile<SyntaxNodePtr> { 78 fn source(&self) -> InFile<SyntaxNodePtr> {
79 self.list_parent_path 79 self.field_list_parent_path
80 .clone() 80 .clone()
81 .map(|path| InFile { file_id: self.file, value: path.into() }) 81 .map(|path| InFile { file_id: self.file, value: path.into() })
82 .unwrap_or_else(|| self.fix_source()) 82 .unwrap_or_else(|| self.fix_source())
@@ -100,6 +100,7 @@ impl AstDiagnostic for MissingFields {
100pub struct MissingPatFields { 100pub struct MissingPatFields {
101 pub file: HirFileId, 101 pub file: HirFileId,
102 pub field_list: AstPtr<ast::RecordPatFieldList>, 102 pub field_list: AstPtr<ast::RecordPatFieldList>,
103 pub field_list_parent_path: Option<AstPtr<ast::Path>>,
103 pub missed_fields: Vec<Name>, 104 pub missed_fields: Vec<Name>,
104} 105}
105 106
@@ -114,6 +115,12 @@ impl Diagnostic for MissingPatFields {
114 fn fix_source(&self) -> InFile<SyntaxNodePtr> { 115 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
115 InFile { file_id: self.file, value: self.field_list.clone().into() } 116 InFile { file_id: self.file, value: self.field_list.clone().into() }
116 } 117 }
118 fn source(&self) -> InFile<SyntaxNodePtr> {
119 self.field_list_parent_path
120 .clone()
121 .map(|path| InFile { file_id: self.file, value: path.into() })
122 .unwrap_or_else(|| self.fix_source())
123 }
117 fn as_any(&self) -> &(dyn Any + Send + 'static) { 124 fn as_any(&self) -> &(dyn Any + Send + 'static) {
118 self 125 self
119 } 126 }
@@ -327,41 +334,6 @@ mod tests {
327 } 334 }
328 335
329 #[test] 336 #[test]
330 fn structure_name_highlighted_for_missing_fields() {
331 check_diagnostics(
332 r#"
333struct Beefy {
334 one: i32,
335 two: i32,
336 three: i32,
337 four: i32,
338 five: i32,
339 six: i32,
340 seven: i32,
341 eight: i32,
342 nine: i32,
343 ten: i32,
344}
345fn baz() {
346 let zz = Beefy {
347 //^^^^^ Missing structure fields:
348 // | - seven
349 one: (),
350 two: (),
351 three: (),
352 four: (),
353 five: (),
354 six: (),
355 eight: (),
356 nine: (),
357 ten: (),
358 };
359}
360"#,
361 );
362 }
363
364 #[test]
365 fn no_such_field_diagnostics() { 337 fn no_such_field_diagnostics() {
366 check_diagnostics( 338 check_diagnostics(
367 r#" 339 r#"
@@ -491,8 +463,8 @@ impl Foo {
491struct S { foo: i32, bar: () } 463struct S { foo: i32, bar: () }
492fn baz(s: S) { 464fn baz(s: S) {
493 let S { foo: _ } = s; 465 let S { foo: _ } = s;
494 //^^^^^^^^^^ Missing structure fields: 466 //^ Missing structure fields:
495 // | - bar 467 //| - bar
496} 468}
497"#, 469"#,
498 ); 470 );
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs
index 3c37fc58e..98959ab68 100644
--- a/crates/ra_hir_ty/src/diagnostics/expr.rs
+++ b/crates/ra_hir_ty/src/diagnostics/expr.rs
@@ -110,8 +110,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
110 self.sink.push(MissingFields { 110 self.sink.push(MissingFields {
111 file: source_ptr.file_id, 111 file: source_ptr.file_id,
112 field_list: AstPtr::new(&field_list), 112 field_list: AstPtr::new(&field_list),
113 field_list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)),
113 missed_fields, 114 missed_fields,
114 list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)),
115 }) 115 })
116 } 116 }
117 } 117 }
@@ -141,6 +141,9 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
141 self.sink.push(MissingPatFields { 141 self.sink.push(MissingPatFields {
142 file: source_ptr.file_id, 142 file: source_ptr.file_id,
143 field_list: AstPtr::new(&field_list), 143 field_list: AstPtr::new(&field_list),
144 field_list_parent_path: record_pat
145 .path()
146 .map(|path| AstPtr::new(&path)),
144 missed_fields, 147 missed_fields,
145 }) 148 })
146 } 149 }
diff --git a/crates/ra_hir_ty/src/diagnostics/match_check.rs b/crates/ra_hir_ty/src/diagnostics/match_check.rs
index 507edcb7d..deca244db 100644
--- a/crates/ra_hir_ty/src/diagnostics/match_check.rs
+++ b/crates/ra_hir_ty/src/diagnostics/match_check.rs
@@ -1161,15 +1161,15 @@ fn main() {
1161 //^ Missing match arm 1161 //^ Missing match arm
1162 match a { 1162 match a {
1163 Either::A { } => (), 1163 Either::A { } => (),
1164 //^^^ Missing structure fields: 1164 //^^^^^^^^^ Missing structure fields:
1165 // | - foo 1165 // | - foo
1166 Either::B => (), 1166 Either::B => (),
1167 } 1167 }
1168 match a { 1168 match a {
1169 //^ Missing match arm 1169 //^ Missing match arm
1170 Either::A { } => (), 1170 Either::A { } => (),
1171 } //^^^ Missing structure fields: 1171 } //^^^^^^^^^ Missing structure fields:
1172 // | - foo 1172 // | - foo
1173 1173
1174 match a { 1174 match a {
1175 Either::A { foo: true } => (), 1175 Either::A { foo: true } => (),