Skip to content

Commit 0ec0292

Browse files
committed
ManualOwnership: disallow @_noImplicitCopy
ManualOwnership effectively subsumes @_noImplicitCopy, by diagnosing all implicit copies in a function.
1 parent da4f27e commit 0ec0292

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,8 @@ ERROR(attr_static_exclusive_no_setters,none,
21482148
// @_manualOwnership
21492149
ERROR(attr_manual_ownership_experimental,none,
21502150
"'@_manualOwnership' requires '-enable-experimental-feature ManualOwnership'", ())
2151+
ERROR(attr_manual_ownership_noimplicitcopy,none,
2152+
"'@_noImplicitCopy' cannot be used with ManualOwnership", ())
21512153

21522154
// @extractConstantsFromMembers
21532155
ERROR(attr_extractConstantsFromMembers_experimental,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ void AttributeChecker::visitNoImplicitCopyAttr(NoImplicitCopyAttr *attr) {
491491
return;
492492
}
493493

494+
// Don't allow it to be combined with ManualOwnership.
495+
if (D->getASTContext().LangOpts.hasFeature(Feature::ManualOwnership)) {
496+
diagnoseAndRemoveAttr(attr, diag::attr_manual_ownership_noimplicitcopy);
497+
}
498+
494499
if (auto *funcDecl = dyn_cast<FuncDecl>(D)) {
495500
if (visitOwnershipAttr(attr))
496501
return;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -enable-experimental-feature NoImplicitCopy \
3+
// RUN: -enable-experimental-feature ManualOwnership
4+
5+
// REQUIRES: swift_feature_ManualOwnership
6+
// REQUIRES: swift_feature_NoImplicitCopy
7+
8+
class C {}
9+
10+
@_manualOwnership
11+
func hello() -> (C, C) {
12+
@_noImplicitCopy let x = C() // expected-error {{'@_noImplicitCopy' cannot be used with ManualOwnership}}
13+
return (x, x)
14+
}

0 commit comments

Comments
 (0)