Skip to content

Commit d192a83

Browse files
committed
[BitwiseCopyable] Remove existential conformance.
It makes sense to form an existential of a type that conforms to `BitwiseCopyable` but such an existential is not itself trivial and consequently not `BitwiseCopyable`.
1 parent a679bbc commit d192a83

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/TypeCheckDecl.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,16 @@ bool
688688
ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
689689
ProtocolDecl *decl) const {
690690
// Marker protocols always self-conform.
691-
if (decl->isMarkerProtocol())
691+
if (decl->isMarkerProtocol()) {
692+
// Except for BitwiseCopyable an existential of which is non-trivial.
693+
auto *bitwiseCopyableProtocol =
694+
decl->getASTContext().getProtocol(KnownProtocolKind::BitwiseCopyable);
695+
if (decl->getASTContext().LangOpts.hasFeature(Feature::BitwiseCopyable) &&
696+
decl == bitwiseCopyableProtocol) {
697+
return false;
698+
}
692699
return true;
700+
}
693701

694702
// Otherwise, if it's not @objc, it conforms to itself only if it has a
695703
// self-conformance witness table.

test/Sema/bitwise_copyable_2.swift

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
struct S_Implicit_Nonescapable {}
1212

1313
struct S_Implicit_Noncopyable : ~Copyable {}
14+
15+
struct S_Explicit_With_Any_BitwiseCopyable : _BitwiseCopyable {
16+
var a: any _BitwiseCopyable // expected-error {{non_bitwise_copyable_type_member}}
17+
}

0 commit comments

Comments
 (0)