mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-10 00:47:45 +00:00
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 <frizi09@gmail.com>
This commit is contained in:
commit
be00d74c7b
@ -39,7 +39,12 @@ pub struct MissingFields {
|
|||||||
|
|
||||||
impl Diagnostic for MissingFields {
|
impl Diagnostic for MissingFields {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"fill structure fields".to_string()
|
use std::fmt::Write;
|
||||||
|
let mut message = String::from("Missing structure fields:\n");
|
||||||
|
for field in &self.missed_fields {
|
||||||
|
write!(message, "- {}\n", field).unwrap();
|
||||||
|
}
|
||||||
|
message
|
||||||
}
|
}
|
||||||
fn source(&self) -> Source<SyntaxNodePtr> {
|
fn source(&self) -> Source<SyntaxNodePtr> {
|
||||||
Source { file_id: self.file, value: self.field_list.into() }
|
Source { file_id: self.file, value: self.field_list.into() }
|
||||||
|
@ -4832,7 +4832,8 @@ fn no_such_field_diagnostics() {
|
|||||||
|
|
||||||
assert_snapshot!(diagnostics, @r###"
|
assert_snapshot!(diagnostics, @r###"
|
||||||
"baz: 62": no such field
|
"baz: 62": no such field
|
||||||
"{\n foo: 92,\n baz: 62,\n }": fill structure fields
|
"{\n foo: 92,\n baz: 62,\n }": Missing structure fields:
|
||||||
|
- bar
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user