From cb0b13a583c0c20b57fd3529e2c01ab42bd8f04d Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 27 Jul 2020 23:32:16 +0300 Subject: Fix another missing fields diagnostics --- crates/ra_hir_ty/src/diagnostics.rs | 50 ++++++++----------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'crates/ra_hir_ty/src/diagnostics.rs') 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 { pub struct MissingFields { pub file: HirFileId, pub field_list: AstPtr, + pub field_list_parent_path: Option>, pub missed_fields: Vec, - pub list_parent_path: Option>, } impl Diagnostic for MissingFields { @@ -76,7 +76,7 @@ impl Diagnostic for MissingFields { } fn source(&self) -> InFile { - self.list_parent_path + self.field_list_parent_path .clone() .map(|path| InFile { file_id: self.file, value: path.into() }) .unwrap_or_else(|| self.fix_source()) @@ -100,6 +100,7 @@ impl AstDiagnostic for MissingFields { pub struct MissingPatFields { pub file: HirFileId, pub field_list: AstPtr, + pub field_list_parent_path: Option>, pub missed_fields: Vec, } @@ -114,6 +115,12 @@ impl Diagnostic for MissingPatFields { fn fix_source(&self) -> InFile { InFile { file_id: self.file, value: self.field_list.clone().into() } } + fn source(&self) -> InFile { + self.field_list_parent_path + .clone() + .map(|path| InFile { file_id: self.file, value: path.into() }) + .unwrap_or_else(|| self.fix_source()) + } fn as_any(&self) -> &(dyn Any + Send + 'static) { self } @@ -326,41 +333,6 @@ mod tests { assert_eq!(annotations, actual); } - #[test] - fn structure_name_highlighted_for_missing_fields() { - check_diagnostics( - r#" -struct Beefy { - one: i32, - two: i32, - three: i32, - four: i32, - five: i32, - six: i32, - seven: i32, - eight: i32, - nine: i32, - ten: i32, -} -fn baz() { - let zz = Beefy { - //^^^^^ Missing structure fields: - // | - seven - one: (), - two: (), - three: (), - four: (), - five: (), - six: (), - eight: (), - nine: (), - ten: (), - }; -} -"#, - ); - } - #[test] fn no_such_field_diagnostics() { check_diagnostics( @@ -491,8 +463,8 @@ impl Foo { struct S { foo: i32, bar: () } fn baz(s: S) { let S { foo: _ } = s; - //^^^^^^^^^^ Missing structure fields: - // | - bar + //^ Missing structure fields: + //| - bar } "#, ); -- cgit v1.2.3