You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clippy_lints/src/missing_field_in_debug.rs
+55-50Lines changed: 55 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ use std::{collections::HashSet, ops::ControlFlow};
2
2
3
3
use clippy_utils::{
4
4
diagnostics::span_lint_and_then,
5
-
match_def_path,
5
+
match_def_path, paths,
6
6
visitors::{for_each_expr,Visitable},
7
7
};
8
8
use if_chain::if_chain;
@@ -20,15 +20,25 @@ use rustc_span::{sym, Span};
20
20
21
21
declare_clippy_lint!{
22
22
/// ### What it does
23
-
/// Checks for manual [`core::fmt::Debug`](https://doc.rust-lang.org/stable/core/fmt/trait.Debug.html) implementations that do not use all fields.
23
+
/// Checks for manual [`core::fmt::Debug`] implementations that do not use all fields.
24
24
///
25
25
/// ### Why is this bad?
26
26
/// A common mistake is to forget to update manual `Debug` implementations when adding a new field
27
27
/// to a struct or a new variant to an enum.
28
28
///
29
-
/// At the same time, it also acts as a style lint to suggest using [`core::fmt::DebugStruct::finish_non_exhaustive`](https://doc.rust-lang.org/stable/core/fmt/struct.DebugStruct.html#method.finish_non_exhaustive)
29
+
/// At the same time, it also acts as a style lint to suggest using [`core::fmt::DebugStruct::finish_non_exhaustive`]
30
30
/// for the times when the user intentionally wants to leave out certain fields (e.g. to hide implementation details).
31
31
///
32
+
/// ### Known problems
33
+
/// This lint works based on the [`DebugStruct`] and [`DebugTuple`] helper types provided by
34
+
/// the [`Formatter`], so this won't detect `Debug` impls that use the `write!` macro.
35
+
/// Oftentimes there is more logic to a `Debug` impl if it uses `write!` macro, so it tries
36
+
/// to be on the conservative side and not lint in those cases in an attempt to prevent false positives.
37
+
///
38
+
/// This lint also does not look through function calls, so calling `.field(self.as_slice())` for example
39
+
/// does not consider fields used inside of `as_slice()` as used by the `Debug` impl.
0 commit comments