mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Fix another missing fields diagnostics
This commit is contained in:
parent
ee1586c1ed
commit
cb0b13a583
3 changed files with 19 additions and 44 deletions
|
@ -59,8 +59,8 @@ impl AstDiagnostic for NoSuchField {
|
||||||
pub struct MissingFields {
|
pub struct MissingFields {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub field_list: AstPtr<ast::RecordExprFieldList>,
|
pub field_list: AstPtr<ast::RecordExprFieldList>,
|
||||||
|
pub field_list_parent_path: Option<AstPtr<ast::Path>>,
|
||||||
pub missed_fields: Vec<Name>,
|
pub missed_fields: Vec<Name>,
|
||||||
pub list_parent_path: Option<AstPtr<ast::Path>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for MissingFields {
|
impl Diagnostic for MissingFields {
|
||||||
|
@ -76,7 +76,7 @@ impl Diagnostic for MissingFields {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
self.list_parent_path
|
self.field_list_parent_path
|
||||||
.clone()
|
.clone()
|
||||||
.map(|path| InFile { file_id: self.file, value: path.into() })
|
.map(|path| InFile { file_id: self.file, value: path.into() })
|
||||||
.unwrap_or_else(|| self.fix_source())
|
.unwrap_or_else(|| self.fix_source())
|
||||||
|
@ -100,6 +100,7 @@ impl AstDiagnostic for MissingFields {
|
||||||
pub struct MissingPatFields {
|
pub struct MissingPatFields {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub field_list: AstPtr<ast::RecordPatFieldList>,
|
pub field_list: AstPtr<ast::RecordPatFieldList>,
|
||||||
|
pub field_list_parent_path: Option<AstPtr<ast::Path>>,
|
||||||
pub missed_fields: Vec<Name>,
|
pub missed_fields: Vec<Name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +115,12 @@ impl Diagnostic for MissingPatFields {
|
||||||
fn fix_source(&self) -> InFile<SyntaxNodePtr> {
|
fn fix_source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile { file_id: self.file, value: self.field_list.clone().into() }
|
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) {
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -326,41 +333,6 @@ mod tests {
|
||||||
assert_eq!(annotations, actual);
|
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]
|
#[test]
|
||||||
fn no_such_field_diagnostics() {
|
fn no_such_field_diagnostics() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
@ -491,8 +463,8 @@ impl Foo {
|
||||||
struct S { foo: i32, bar: () }
|
struct S { foo: i32, bar: () }
|
||||||
fn baz(s: S) {
|
fn baz(s: S) {
|
||||||
let S { foo: _ } = s;
|
let S { foo: _ } = s;
|
||||||
//^^^^^^^^^^ Missing structure fields:
|
//^ Missing structure fields:
|
||||||
// | - bar
|
//| - bar
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,8 +110,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
self.sink.push(MissingFields {
|
self.sink.push(MissingFields {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
field_list: AstPtr::new(&field_list),
|
field_list: AstPtr::new(&field_list),
|
||||||
|
field_list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)),
|
||||||
missed_fields,
|
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 {
|
self.sink.push(MissingPatFields {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
field_list: AstPtr::new(&field_list),
|
field_list: AstPtr::new(&field_list),
|
||||||
|
field_list_parent_path: record_pat
|
||||||
|
.path()
|
||||||
|
.map(|path| AstPtr::new(&path)),
|
||||||
missed_fields,
|
missed_fields,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1161,15 +1161,15 @@ fn main() {
|
||||||
//^ Missing match arm
|
//^ Missing match arm
|
||||||
match a {
|
match a {
|
||||||
Either::A { } => (),
|
Either::A { } => (),
|
||||||
//^^^ Missing structure fields:
|
//^^^^^^^^^ Missing structure fields:
|
||||||
// | - foo
|
// | - foo
|
||||||
Either::B => (),
|
Either::B => (),
|
||||||
}
|
}
|
||||||
match a {
|
match a {
|
||||||
//^ Missing match arm
|
//^ Missing match arm
|
||||||
Either::A { } => (),
|
Either::A { } => (),
|
||||||
} //^^^ Missing structure fields:
|
} //^^^^^^^^^ Missing structure fields:
|
||||||
// | - foo
|
// | - foo
|
||||||
|
|
||||||
match a {
|
match a {
|
||||||
Either::A { foo: true } => (),
|
Either::A { foo: true } => (),
|
||||||
|
|
Loading…
Reference in a new issue