Skip to content

Commit fef04f5

Browse files
committed
allow @_moveOnly only on structs or enums
Per the existing proposal, we're not supporting move-only reference types right now.
1 parent eecde02 commit fef04f5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6704,7 +6704,7 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
67046704
(TypeRepr*, StringRef))
67056705

67066706
ERROR(moveOnly_not_allowed_here,none,
6707-
"'moveOnly' may only be applied to classes, structs, and enums", ())
6707+
"'moveOnly' only applies to structs or enums", ())
67086708
ERROR(move_expression_not_passed_lvalue,none,
67096709
"'move' can only be applied to lvalues", ())
67106710
ERROR(borrow_expression_not_passed_lvalue,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
20962096
return;
20972097
}
20982098

2099-
if (isa<NominalTypeDecl>(D))
2099+
if (isa<StructDecl>(D) || isa<EnumDecl>(D))
21002100
return;
21012101

21022102
diagnose(attr->getLocation(), diag::moveOnly_not_allowed_here)

test/Sema/moveonly_decl_attr.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import Swift
44

5-
@_moveOnly
6-
class C {
5+
@_moveOnly class C { // expected-error {{'moveOnly' only applies to structs or enums}}{{1-12=}}
76
@_moveOnly // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
87
func foo() {}
98
}
@@ -21,3 +20,7 @@ enum E {
2120
}
2221

2322
@_moveOnly let l = C() // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}
23+
24+
@_moveOnly protocol P {} // expected-error {{'moveOnly' only applies to structs or enums}}{{1-12=}}
25+
@_moveOnly actor A {} // expected-error {{'moveOnly' only applies to structs or enums}}{{1-12=}}
26+
@_moveOnly extension C {} // expected-error {{'@_moveOnly' attribute cannot be applied to this declaration}}{{1-12=}}

0 commit comments

Comments
 (0)