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 {
}
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())
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>,
}
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
}
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(
struct S { foo: i32, bar: () }
fn baz(s: S) {
let S { foo: _ } = s;
- //^^^^^^^^^^ Missing structure fields:
- // | - bar
+ //^ Missing structure fields:
+ //| - bar
}
"#,
);
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)),
})
}
}
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,
})
}