]> git.lizzy.rs Git - rust.git/commitdiff
Fix another missing fields diagnostics
authorKirill Bulatov <mail4score@gmail.com>
Mon, 27 Jul 2020 20:32:16 +0000 (23:32 +0300)
committerKirill Bulatov <mail4score@gmail.com>
Tue, 11 Aug 2020 12:09:08 +0000 (15:09 +0300)
crates/ra_hir_ty/src/diagnostics.rs
crates/ra_hir_ty/src/diagnostics/expr.rs
crates/ra_hir_ty/src/diagnostics/match_check.rs

index a4cede81dc704348e4491d9d2d407404bab122a4..48b578fb0ee89ecca6aaf95f7bb1a4d3b3f4d97f 100644 (file)
@@ -59,8 +59,8 @@ fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
 pub struct MissingFields {
     pub file: HirFileId,
     pub field_list: AstPtr<ast::RecordExprFieldList>,
+    pub field_list_parent_path: Option<AstPtr<ast::Path>>,
     pub missed_fields: Vec<Name>,
-    pub list_parent_path: Option<AstPtr<ast::Path>>,
 }
 
 impl Diagnostic for MissingFields {
@@ -76,7 +76,7 @@ fn fix_source(&self) -> InFile<SyntaxNodePtr> {
     }
 
     fn source(&self) -> InFile<SyntaxNodePtr> {
-        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 @@ fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
 pub struct MissingPatFields {
     pub file: HirFileId,
     pub field_list: AstPtr<ast::RecordPatFieldList>,
+    pub field_list_parent_path: Option<AstPtr<ast::Path>>,
     pub missed_fields: Vec<Name>,
 }
 
@@ -114,6 +115,12 @@ fn message(&self) -> String {
     fn fix_source(&self) -> InFile<SyntaxNodePtr> {
         InFile { file_id: self.file, value: self.field_list.clone().into() }
     }
+    fn source(&self) -> InFile<SyntaxNodePtr> {
+        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 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
         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 @@ fn missing_record_pat_field_diagnostic() {
 struct S { foo: i32, bar: () }
 fn baz(s: S) {
     let S { foo: _ } = s;
-        //^^^^^^^^^^ Missing structure fields:
-        //         | - bar
+      //^ Missing structure fields:
+      //| - bar
 }
 "#,
         );
index 3c37fc58e924157c15a6fd77969c48d27e66b649..98959ab684ae90423646f4a9bed41f49da2ac765 100644 (file)
@@ -110,8 +110,8 @@ fn create_record_literal_missing_fields_diagnostic(
                     self.sink.push(MissingFields {
                         file: source_ptr.file_id,
                         field_list: AstPtr::new(&field_list),
+                        field_list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)),
                         missed_fields,
-                        list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)),
                     })
                 }
             }
@@ -141,6 +141,9 @@ fn create_record_pattern_missing_fields_diagnostic(
                         self.sink.push(MissingPatFields {
                             file: source_ptr.file_id,
                             field_list: AstPtr::new(&field_list),
+                            field_list_parent_path: record_pat
+                                .path()
+                                .map(|path| AstPtr::new(&path)),
                             missed_fields,
                         })
                     }
index 507edcb7def8ca3cb8fcc629fb0ba0b260bbb895..deca244dbbab5956f098401070a81aa398f9eb81 100644 (file)
@@ -1161,15 +1161,15 @@ fn main() {
         //^ Missing match arm
     match a {
         Either::A { } => (),
-                //^^^ Missing structure fields:
-                //  | - foo
+      //^^^^^^^^^ Missing structure fields:
+      //        | - foo
         Either::B => (),
     }
     match a {
         //^ Missing match arm
         Either::A { } => (),
-    }           //^^^ Missing structure fields:
-                //  | - foo
+    } //^^^^^^^^^ Missing structure fields:
+      //        | - foo
 
     match a {
         Either::A { foo: true } => (),