Skip to content

Commit 66f04e6

Browse files
committed
Show missing struct fields in the error message
1 parent ac9ba5e commit 66f04e6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/ra_hir/src/diagnostics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ pub struct MissingFields {
3939

4040
impl Diagnostic for MissingFields {
4141
fn message(&self) -> String {
42-
"fill structure fields".to_string()
42+
use std::fmt::Write;
43+
let mut message = String::from("Missing structure fields:\n");
44+
for field in &self.missed_fields {
45+
write!(message, "- {}\n", field).unwrap();
46+
}
47+
message
4348
}
4449
fn source(&self) -> Source<SyntaxNodePtr> {
4550
Source { file_id: self.file, value: self.field_list.into() }

crates/ra_hir/src/ty/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4832,7 +4832,8 @@ fn no_such_field_diagnostics() {
48324832

48334833
assert_snapshot!(diagnostics, @r###"
48344834
"baz: 62": no such field
4835-
"{\n foo: 92,\n baz: 62,\n }": fill structure fields
4835+
"{\n foo: 92,\n baz: 62,\n }": Missing structure fields:
4836+
- bar
48364837
"###
48374838
);
48384839
}

0 commit comments

Comments
 (0)