diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 3f20ec0483219..c2249e514e57f 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -8200,6 +8200,21 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint( return SolutionKind::Solved; } + // Copyable is checked structurally, so for better performance, split apart + // this constraint into individual Copyable constraints on each tuple element. + if (auto *tupleType = type->getAs()) { + if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) { + for (unsigned i = 0, e = tupleType->getNumElements(); i < e; ++i) { + addConstraint(ConstraintKind::ConformsTo, + tupleType->getElementType(i), + protocol->getDeclaredInterfaceType(), + locator.withPathElement(LocatorPathElt::TupleElement(i))); + } + + return SolutionKind::Solved; + } + } + auto *loc = getConstraintLocator(locator); /// Record the given conformance as the result, adding any conditional diff --git a/test/Constraints/moveonly_constraints.swift b/test/Constraints/moveonly_constraints.swift index 188efa795c19d..772b0df439e86 100644 --- a/test/Constraints/moveonly_constraints.swift +++ b/test/Constraints/moveonly_constraints.swift @@ -88,8 +88,8 @@ func testBasic(_ mo: borrowing MO) { genericVarArg(5) genericVarArg(mo) // expected-error {{move-only type 'MO' cannot be used with generics yet}} - takeGeneric( (mo, 5) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to '_Copyable'}} - takeGenericSendable((mo, mo)) // expected-error 2{{global function 'takeGenericSendable' requires that 'MO' conform to '_Copyable'}} + takeGeneric( (mo, 5) ) // expected-error {{move-only type 'MO' cannot be used with generics yet}} + takeGenericSendable((mo, mo)) // expected-error 2{{move-only type 'MO' cannot be used with generics yet}} let singleton : (MO) = (mo) takeGeneric(singleton) // expected-error {{move-only type 'MO' cannot be used with generics yet}}