Closed
Description
What it does
This lint finds fields that implement Debug but are not printed in a struct's Debug implementation.
This lint would ignore fields in types that do not implement Debug.
Lint Name
debug_missing_field
Category
style, pedantic
Advantage
- When adding a new field to a type that implements Debug manually, you may forget to update the Debug implementation. This lint would ensure new fields are linted if not printed in the debug implementation.
Drawbacks
- Both tuple and struct debug implementations need to be considered.
- Enums are a little more complicated to lint, since you would need check the fields of each variant.
- The lint may have false positives if the Debug implementation uses manual write! invocations instead of debug_struct and debug_tuple.
Example
pub struct Example {
non_debug: NonDebug,
debug: u32,
new: u16,
}
impl Debug for Example {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Example").field("debug", &self.debug).finish_non_exhaustive()
}
}
Could be written as:
pub struct Example {
non_debug: NonDebug,
debug: u32,
new: u16,
}
impl Debug for Example {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Example").field("debug", &self.debug).field("new", &self.new).finish_non_exhaustive()
}
}