Description
Code
struct S {
ant: u32,
bat: u32,
cat: u32,
dog: u32,
elephant: u32,
fish: u32,
giraffe: u32
}
fn main() {
let s = S {
ant: 1,
bat: 2,
cat: 3,
dog: 4,
elephant: 5,
fish: 6,
zebra: 7
};
}
Current output
error[E0560]: struct `S` has no field named `zebra`
--> src/main.rs:20:9
|
20 | zebra: 7
| ^^^^^ `S` does not have this field
|
= note: available fields are: `ant`, `bat`, `cat`, `dog`, `elephant` ... and 2 others
Desired output
error[E0560]: struct `S` has no field named `zebra`
--> src/main.rs:20:9
|
20 | zebra: 7
| ^^^^^ `S` does not have this field
|
= note: unassigned fields are: `giraffe`
Rationale and extra context
We can't set a field on a struct more than once, so we can discount those already (likely correctly) set fields from the set of available fields to choose from. This is especially useful if you're only following the compiler error messages as the current error output does not mention giraffe
in the error message. If I'm coding blind I get prompted correctly what the first few fields of the struct are named, but once I've filled in the first 5 fields correctly there's no more hints on the other fields. If we exclude the fields we've already filled in then rustc should be able to hint me to get to the end of a struct no matter how many fields it has (after a few compiles as I fill in what I need to).
Other cases
This would be especially useful if I am filling out a struct that has been autogenerated by some macro and I can't easily view the source of it.
Anything else?
This just seems like a cute quality of life improvement in the diagnostics.
(I'm hoping it's not too difficult to implement)