Fix another missing fields diagnostics

This commit is contained in:
Kirill Bulatov 2020-07-27 23:32:16 +03:00
parent ee1586c1ed
commit cb0b13a583
3 changed files with 19 additions and 44 deletions

View file

@ -59,8 +59,8 @@ impl AstDiagnostic for NoSuchField {
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 @@ impl Diagnostic for MissingFields {
}
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 @@ impl AstDiagnostic for MissingFields {
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 @@ impl Diagnostic for MissingPatFields {
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 @@ 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
}
"#,
);

View file

@ -110,8 +110,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
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 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
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,
})
}

View 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 } => (),