Don't print inherited, synthesized protocols

This commit is contained in:
Doug Gregor
2021-07-01 16:07:51 -07:00
parent fbf9708bfc
commit 83827e7fdb

View File

@@ -357,7 +357,8 @@ class InheritedProtocolCollector {
/// For each type in \p directlyInherited, classify the protocols it refers to
/// as included for printing or not, and record them in the appropriate
/// vectors.
void recordProtocols(ArrayRef<TypeLoc> directlyInherited, const Decl *D) {
void recordProtocols(ArrayRef<TypeLoc> directlyInherited, const Decl *D,
bool skipSynthesized = false) {
Optional<AvailableAttrList> availableAttrs;
for (TypeLoc inherited : directlyInherited) {
@@ -378,6 +379,9 @@ class InheritedProtocolCollector {
// any of those besides 'AnyObject'.
}
if (skipSynthesized)
return;
// Check for synthesized protocols, like Hashable on enums.
if (auto *nominal = dyn_cast<NominalTypeDecl>(D)) {
SmallVector<ProtocolConformance *, 4> localConformances =
@@ -455,7 +459,8 @@ public:
if (auto *CD = dyn_cast<ClassDecl>(D)) {
for (auto *SD = CD->getSuperclassDecl(); SD;
SD = SD->getSuperclassDecl()) {
map[nominal].recordProtocols(SD->getInherited(), SD);
map[nominal].recordProtocols(
SD->getInherited(), SD, /*skipSynthesized=*/true);
for (auto *Ext: SD->getExtensions()) {
if (shouldInclude(Ext)) {
map[nominal].recordProtocols(Ext->getInherited(), Ext);