@@ -6973,44 +6973,31 @@ void GenericSignatureBuilder::checkConformanceConstraints(
6973
6973
}
6974
6974
6975
6975
void GenericSignatureBuilder::diagnoseRedundantRequirements () const {
6976
- SmallVector<ExplicitRequirement, 2 > redundantRequirements;
6977
-
6978
- for (auto pair : Impl->RedundantRequirements ) {
6979
- auto *source = pair.first .getSource ();
6976
+ for (const auto &req : Impl->ExplicitRequirements ) {
6977
+ auto *source = req.getSource ();
6978
+ auto loc = source->getLoc ();
6980
6979
6981
6980
// Don't diagnose anything without a source location.
6982
- if (source-> getLoc () .isInvalid ())
6981
+ if (loc .isInvalid ())
6983
6982
continue ;
6984
6983
6985
- // Don't diagnose redundant inferred requirements.
6984
+ // Don't diagnose inferred requirements.
6986
6985
if (source->isInferredRequirement ())
6987
6986
continue ;
6988
6987
6988
+ // Check if its actually redundant.
6989
+ auto found = Impl->RedundantRequirements .find (req);
6990
+ if (found == Impl->RedundantRequirements .end ())
6991
+ continue ;
6992
+
6989
6993
// Don't diagnose explicit requirements that are implied by
6990
6994
// inferred requirements.
6991
- if (llvm::all_of (pair. second ,
6995
+ if (llvm::all_of (found-> second ,
6992
6996
[&](const ExplicitRequirement &otherReq) {
6993
6997
return otherReq.getSource ()->isInferredRequirement ();
6994
6998
}))
6995
6999
continue ;
6996
7000
6997
- redundantRequirements.push_back (pair.first );
6998
- }
6999
-
7000
- auto &SM = Context.SourceMgr ;
7001
-
7002
- std::sort (redundantRequirements.begin (), redundantRequirements.end (),
7003
- [&](ExplicitRequirement lhs, ExplicitRequirement rhs) {
7004
- return compareSourceLocs (SM,
7005
- lhs.getSource ()->getLoc (),
7006
- rhs.getSource ()->getLoc ());
7007
- });
7008
-
7009
- for (const auto &req : redundantRequirements) {
7010
- auto *source = req.getSource ();
7011
- auto loc = source->getLoc ();
7012
- assert (loc.isValid ());
7013
-
7014
7001
auto subjectType = getSugaredDependentType (source->getStoredType (),
7015
7002
getGenericParams ());
7016
7003
@@ -7039,7 +7026,7 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
7039
7026
Context.Diags .diagnose (loc, diag::redundant_conformance_constraint,
7040
7027
subjectType, proto);
7041
7028
7042
- for (auto otherReq : Impl-> RedundantRequirements [req] ) {
7029
+ for (auto otherReq : found-> second ) {
7043
7030
auto *otherSource = otherReq.getSource ();
7044
7031
auto otherLoc = otherSource->getLoc ();
7045
7032
if (otherLoc.isInvalid ())
0 commit comments