Skip to content

Commit be00d74

Browse files
bors[bot]Frizi
andauthored
Merge #2388
2388: Show missing struct fields in the error message r=matklad a=Frizi This provides the most interesting information about the "missing structure fields" error directly to the user. Co-authored-by: Frizi <[email protected]>
2 parents df25dd4 + 66f04e6 commit be00d74

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)