Ignore derived Clone and Debug implementations during dead code analysis by FabianWolff · Pull Request #85200 · rust-lang/rust (original) (raw)

Thanks for your comments everyone, and thanks for your review and suggestions @lcnr!

I have implemented them now, along with the suggestion to ignore all automatically derived impls, not just those of Clone and Debug. Predictably, this caused more warnings in the compiler and library code, and as it turned out, many of the fields now (correctly, when ignoring automatically derived impls) marked as "never read" are actually necessary. One example is ordering versions: The fields major, minor, and patch are never explicitly read, but versions are compared, so the fields do have an effect:

if sess.assume_incomplete_release {
rustc_version > min_version
} else {
rustc_version >= min_version
}

I have prefixed such field names with underscores for now to silence the warning. I think that's acceptable, because the underscore makes explicit that the field is needed only for its "side-effects" (e.g. on ordering).

Also keep in mind that I have already removed most of the actually unnecessary fields in an earlier commit, so the above doesn't mean that this change causes unreasonably many false positives.