Skip to content

Commit 2557ba9

Browse files
committed
Noncopyable: deprecate '@_moveOnly' attribute
This hidden attribute is a leftover from before the '~Copyable' syntax. rdar://130526083
1 parent 653e224 commit 2557ba9

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7743,6 +7743,8 @@ ERROR(noncopyable_objc_enum, none,
77437743
"noncopyable enums cannot be marked '@objc'", ())
77447744
ERROR(moveOnly_not_allowed_here,none,
77457745
"'@_moveOnly' attribute is only valid on structs or enums", ())
7746+
ERROR(moveOnly_deprecated,none,
7747+
"'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead", ())
77467748
ERROR(consume_expression_needed_for_cast,none,
77477749
"implicit conversion to %0 is consuming", (Type))
77487750
NOTE(add_consume_to_silence,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,12 @@ void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
25462546
}
25472547

25482548
void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
2549+
// This attribute is deprecated and slated for removal.
2550+
diagnose(attr->getLocation(), diag::moveOnly_deprecated)
2551+
.fixItRemove(attr->getRange())
2552+
.warnInSwiftInterface(D->getDeclContext());
2553+
2554+
25492555
if (isa<StructDecl>(D) || isa<EnumDecl>(D))
25502556
return;
25512557

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ extension UnownedJob: CustomStringConvertible {
193193
@available(SwiftStdlib 5.9, *)
194194
@available(*, deprecated, renamed: "ExecutorJob")
195195
@frozen
196-
@_moveOnly
197-
public struct Job: Sendable {
196+
public struct Job: Sendable, ~Copyable {
198197
internal var context: Builtin.Job
199198

200199
@usableFromInline
@@ -262,8 +261,7 @@ extension Job {
262261
/// you don't generally interact with jobs directly.
263262
@available(SwiftStdlib 5.9, *)
264263
@frozen
265-
@_moveOnly
266-
public struct ExecutorJob: Sendable {
264+
public struct ExecutorJob: Sendable, ~Copyable {
267265
internal var context: Builtin.Job
268266

269267
@usableFromInline

test/Sema/moveonly_decl_attr.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
// RUN: %target-typecheck-verify-swift -parse-stdlib -disable-availability-checking
2-
3-
import Swift
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
42

3+
// expected-error@+1 {{'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead}}
54
@_moveOnly class C { // expected-error {{'@_moveOnly' attribute is only valid on structs or enums}}{{1-12=}}
65
@_moveOnly // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
76
func foo() {}
87
}
98

10-
@_moveOnly
11-
struct S {
9+
// expected-error@+1 {{'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead}}
10+
@_moveOnly struct S {
1211
@_moveOnly // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
1312
func foo() {}
1413
}
1514

16-
@_moveOnly
17-
enum E {
15+
// expected-error@+1 {{'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead}}
16+
@_moveOnly enum E {
1817
@_moveOnly // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
1918
func foo() {}
2019
}
2120

2221
@_moveOnly let l = C() // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
2322

23+
// expected-error@+1 {{'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead}}
2424
@_moveOnly protocol P {} // expected-error {{'@_moveOnly' attribute is only valid on structs or enums}}{{1-12=}}
25+
// expected-error@+1 {{'@_moveOnly' attribute is deprecated and will be removed; use '~Copyable' instead}}
2526
@_moveOnly actor A {} // expected-error {{'@_moveOnly' attribute is only valid on structs or enums}}{{1-12=}}
2627
@_moveOnly extension C {} // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}{{1-12=}}

0 commit comments

Comments
 (0)