new lint: missing_fields_in_debug - #10616
Conversation
|
r? @Alexendoo (rustbot has picked a reviewer for you, use r? to override) |
|
☔ The latest upstream changes (presumably #10578) made this pull request unmergeable. Please resolve the merge conflicts. |
003ffb3 to
fc86d55
Compare
|
☔ The latest upstream changes (presumably #10647) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Is there anything else or is it just waiting on a rebase? |
|
Sorry for the delay, can't remember if I had anything else in mind so I just read it over again this weekend 😄 A thought that came to me just now is maybe we don't actually need to lint enums, unlike structs where it's very easy to add a new field and forget to update the |
That's a very good point, I agree with this. I went ahead and removed the enum checking (and also addressed the other comments). That made me realize that one can do something similar with structs by destructuring struct F { a: i32, b: i32 }
impl fmt::Debug for F {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self { a } = self; // error, b not handled
// ...
}
}Although a lint for this would still be nice 😅 |
|
Thanks! Yeah that's a good way of catching it With a rebase for the conflicts I'd say this is ready to merge |
move some strings into consts, more tests s/missing_field_in_debug/missing_fields_in_debug dont trigger in macro expansions make dogfood tests happy minor cleanups replace HashSet with FxHashSet replace match_def_path with match_type if_chain -> let chains, fix markdown, allow newtype pattern fmt consider string literal in `.field()` calls as used don't intern defined symbol, remove mentions of 'debug_tuple' special-case PD, account for field access through `Deref`
bfb696b to
a859b0e
Compare
|
👍 @bors r+ |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #10429
This PR adds a new lint that looks for manual
Debugimplementations that do not "use" all of the fields.This often happens when adding a new field to a struct.
It also acts as a style lint in case leaving out a field was intentional. In that case, it's preferred to use
DebugStruct::finish_non_exhaustive, which indicates that there are more fields that were explicitly not shown.