[missing_fields_in_debug
]: make sure self type is an adt
#11069
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #11063, another ICE that can only happen in core.
This lint needs the
DefId
of the implementor to get its fields, but that ICEs if the implementor does not have aDefId
(as is the case with primitive types, e.g.impl Debug for bool
), which is where this ICE comes from.This PR changes the check I added in #10897 to be more... robust against
Debug
implementations we don't want to lint.Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue.
That prevents weird edge cases like this one that can only happen in core.
Again, I don't know if it's even possible to add a test case for this since one cannot implement
Debug
for primitive types outside of the crate that definedDebug
(core).I did make sure that this PR no longer ICEs on
impl<T> Debug for T
andimpl Debug for bool
.Maybe writing such a test is possible with
#![no_core]
and then re-defining theDebug
trait or something like that...?changelog: [
missing_fields_in_debug
]: make sure self type is an adt (fixes an ICE in core)r? @Alexendoo (reviewed the last PRs for this lint)