[NFC] Refactor DerivedConformances code to reduce diagnostics code duplication #32884
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.
This is a follow-up to #32797.
There was some code duplication for emitting new diagnostic notes for
Comparable
synthesis failures, so I have pulled the common code out for diagnosing derived conformance failures into separate functions which can be reused to emit the diagnostics.diagnoseAnyNonConformingMemberTypes
diagnoses any members of the conforming type that does not conform to the protocol we were trying to synthesise the conformance to. For example,Comparable
synthesis requires the members of the conforming type to also beComparable
and using this method we can diagnose any members which does not conform toComparable
.diagnoseIfSynthesisUnsupportedForDecl
diagnoses the conforming type if we do not support derived conformances for that type. For example,Equatable
synthesis is not supported for classes and using this method we can diagnose a given class type.storedPropertiesNotConformingToProtocol
returns any stored properties of a struct which do not conform to a given protocol. For example,diagnoseNonConformingMemberTypes
uses this method to find the struct members which do not conform to the type for which we're trying to synthesise the conformance to. It is also used incanDeriveConformance
to figure out if we can synthesiseEquatable
orHashable
for a struct.