Skip to content

Commit e8e82eb

Browse files
committed
[wip] update tests to use ~Copyable instead of the attribute
1 parent 9f45b9e commit e8e82eb

File tree

3 files changed

+30
-54
lines changed

3 files changed

+30
-54
lines changed

test/Sema/moveonly_illegal_types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class Klass {}
1414
let asdf: any Hashable & Klass
1515

1616
// a concrete move-only type
17-
@_moveOnly struct MO {
17+
struct MO : ~Copyable {
1818
var x: Int?
1919
}
2020

21-
@_moveOnly struct GenericMO<T> {
21+
struct GenericMO<T> : ~Copyable {
2222
var t: T
2323
}
2424

test/Sema/moveonly_restrictions.swift

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
class CopyableKlass {}
66

7-
@_moveOnly
8-
class MoveOnlyKlass {
7+
class MoveOnlyKlass: ~Copyable {
98
init?() {} // expected-error {{move-only types cannot have failable initializers yet}}
109
}
1110

12-
@_moveOnly
13-
class MoveOnlyStruct {
11+
class MoveOnlyStruct: ~Copyable {
1412
init?(one: Bool) {} // expected-error {{move-only types cannot have failable initializers yet}}
1513
init!(two: Bool) {} // expected-error {{move-only types cannot have failable initializers yet}}
1614
}
@@ -21,8 +19,7 @@ class C {
2119
var moveOnlyS: MoveOnlyStruct? = nil // expected-error {{move-only type 'MoveOnlyStruct' cannot be used with generics yet}}
2220
}
2321

24-
@_moveOnly
25-
class CMoveOnly {
22+
class CMoveOnly: ~Copyable {
2623
var copyable: CopyableKlass? = nil
2724
var moveOnlyC: MoveOnlyKlass? = nil // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
2825
var moveOnlyS: MoveOnlyStruct? = nil // expected-error {{move-only type 'MoveOnlyStruct' cannot be used with generics yet}}
@@ -47,11 +44,10 @@ struct S { // expected-error {{struct 'S' cannot contain a move-only type withou
4744
var moveOnly2: MoveOnlyStruct? // expected-error {{move-only type 'MoveOnlyStruct' cannot be used with generics yet}}
4845
var moveOnly: MoveOnlyStruct // expected-note {{contained move-only property 'S.moveOnly'}}
4946
var moveOnly3: OptionalGrandField<MoveOnlyKlass> // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
50-
var moveOnly3: OptionalGrandField<MoveOnlyStruct> // expected-error {{move-only type 'MoveOnlyStruct' cannot be used with generics yet}}
47+
var moveOnly4: OptionalGrandField<MoveOnlyStruct> // expected-error {{move-only type 'MoveOnlyStruct' cannot be used with generics yet}}
5148
}
5249

53-
@_moveOnly
54-
struct SMoveOnly {
50+
struct SMoveOnly: ~Copyable {
5551
var copyable: CopyableKlass
5652
var moveOnly: MoveOnlyKlass
5753
}
@@ -62,8 +58,7 @@ enum E { // expected-error {{enum 'E' cannot contain a move-only type without al
6258
case rhs2(OptionalGrandField<MoveOnlyKlass>) // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
6359
}
6460

65-
@_moveOnly
66-
enum EMoveOnly {
61+
enum EMoveOnly: ~Copyable {
6762
case lhs(CopyableKlass)
6863
case rhs(MoveOnlyKlass)
6964

@@ -84,8 +79,7 @@ func foo() {
8479
var moveOnly: MoveOnlyKlass? = nil // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
8580
}
8681

87-
@_moveOnly
88-
class C2MoveOnly {
82+
class C2MoveOnly: ~Copyable {
8983
var copyable: CopyableKlass? = nil
9084
var moveOnly: MoveOnlyKlass? = nil // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
9185
}
@@ -95,8 +89,7 @@ func foo() {
9589
var moveOnly: MoveOnlyKlass // expected-note {{contained move-only property 'S2.moveOnly'}}
9690
}
9791

98-
@_moveOnly
99-
struct S2MoveOnly {
92+
struct S2MoveOnly: ~Copyable {
10093
var copyable: CopyableKlass
10194
var moveOnly: MoveOnlyKlass
10295
}
@@ -106,8 +99,7 @@ func foo() {
10699
case rhs(MoveOnlyKlass) // expected-note {{contained move-only enum case 'E2.rhs'}}
107100
}
108101

109-
@_moveOnly
110-
enum E2MoveOnly {
102+
enum E2MoveOnly: ~Copyable {
111103
case lhs(CopyableKlass)
112104
case rhs(MoveOnlyKlass)
113105
}
@@ -117,8 +109,7 @@ func foo() {
117109
var moveOnly: MoveOnlyKlass? = nil // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
118110
}
119111

120-
@_moveOnly
121-
class C3MoveOnly {
112+
class C3MoveOnly: ~Copyable {
122113
var copyable: CopyableKlass? = nil
123114
var moveOnly: MoveOnlyKlass? = nil // expected-error {{move-only type 'MoveOnlyKlass' cannot be used with generics yet}}
124115
}
@@ -128,8 +119,7 @@ func foo() {
128119
var moveOnly: MoveOnlyKlass // expected-note {{contained move-only property 'S3.moveOnly'}}
129120
}
130121

131-
@_moveOnly
132-
struct S3MoveOnly {
122+
struct S3MoveOnly: ~Copyable {
133123
var copyable: CopyableKlass
134124
var moveOnly: MoveOnlyKlass
135125
}
@@ -139,8 +129,7 @@ func foo() {
139129
case rhs(MoveOnlyKlass) // expected-note {{contained move-only enum case 'E3.rhs'}}
140130
}
141131

142-
@_moveOnly
143-
enum E3MoveOnly {
132+
enum E3MoveOnly: ~Copyable {
144133
case lhs(CopyableKlass)
145134
case rhs(MoveOnlyKlass)
146135
}
@@ -161,11 +150,11 @@ struct UnsafePointerWithOwner<T> {
161150
// protocol.
162151
protocol P {}
163152
protocol Q {}
164-
@_moveOnly class ProtocolCheckMoveOnlyKlass {}
165-
@_moveOnly struct ProtocolCheckMoveOnlyStruct {
153+
class ProtocolCheckMoveOnlyKlass: ~Copyable {}
154+
struct ProtocolCheckMoveOnlyStruct: ~Copyable {
166155
var k: MoveOnlyKlass
167156
}
168-
@_moveOnly enum ProtocolCheckMoveOnlyEnum {}
157+
enum ProtocolCheckMoveOnlyEnum: ~Copyable {}
169158

170159
extension ProtocolCheckMoveOnlyKlass : P {} // expected-error {{move-only class 'ProtocolCheckMoveOnlyKlass' cannot conform to 'P'}}
171160
extension ProtocolCheckMoveOnlyStruct : P, Q {}
@@ -193,19 +182,15 @@ extension ProtocolCheckMoveOnlyStruct {}
193182
extension ProtocolCheckMoveOnlyEnum {}
194183

195184
// Check if we define a move only type and make it conform on the base type
196-
@_moveOnly
197-
class MoveOnlyKlassP : P {} // expected-error {{move-only class 'MoveOnlyKlassP' cannot conform to 'P'}}
198-
@_moveOnly
199-
struct MoveOnlyStructP : P { // expected-error {{move-only struct 'MoveOnlyStructP' cannot conform to 'P'}}
185+
class MoveOnlyKlassP : P, ~Copyable {} // expected-error {{move-only class 'MoveOnlyKlassP' cannot conform to 'P'}}
186+
struct MoveOnlyStructP : ~Copyable, P { // expected-error {{move-only struct 'MoveOnlyStructP' cannot conform to 'P'}}
200187
var mv: MoveOnlyKlass
201188
}
202-
@_moveOnly
203-
enum MoveOnlyEnumP : P {} // expected-error {{move-only enum 'MoveOnlyEnumP' cannot conform to 'P'}}
189+
enum MoveOnlyEnumP : ~Copyable, P {} // expected-error {{move-only enum 'MoveOnlyEnumP' cannot conform to 'P'}}
204190

205191
// ensure there is no auto-synthesis of Equatable, Hashable, etc, for this move-only enum,
206192
// because it normally would be synthesized since it only has cases without associated values.
207-
@_moveOnly
208-
enum Color {
193+
enum Color: ~Copyable {
209194
case red
210195
case green
211196
case blue
@@ -216,8 +201,7 @@ enum Color {
216201
}
217202
}
218203

219-
@_moveOnly
220-
enum StrengthLevel: Int { // ensure move-only raw enums do not conform to RawRepresentable
204+
enum StrengthLevel: Int, ~Copyable { // ensure move-only raw enums do not conform to RawRepresentable
221205
case none = 0
222206
case low
223207
case high

test/Sema/moveonly_sendable.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
struct CopyableStruct {}
77
class Ref { var x = 0 } // expected-note 3{{class 'Ref' does not conform to the 'Sendable' protocol}}
88

9-
@_moveOnly
10-
struct FileDescriptor: Sendable {
9+
struct FileDescriptor: ~Copyable, Sendable {
1110
var id = 0
1211
}
1312

14-
@_moveOnly
15-
enum MaybeFile { // should implicitly conform
13+
enum MaybeFile: ~Copyable { // should implicitly conform
1614
case available(FileDescriptor)
1715
case closed
1816
}
1917

20-
@_moveOnly
21-
struct NotSendableMO { // expected-note 2{{consider making struct 'NotSendableMO' conform to the 'Sendable' protocol}}
18+
struct NotSendableMO: ~Copyable { // expected-note 2{{consider making struct 'NotSendableMO' conform to the 'Sendable' protocol}}
2219
var ref: Ref
2320
}
2421

@@ -66,26 +63,22 @@ func caller() async {
6663

6764
// now make sure you can't form a Sendable existential from a move-only type.
6865

69-
@_moveOnly
70-
struct RefPair: Sendable {
66+
struct RefPair: Sendable, ~Copyable {
7167
var left: Ref // expected-warning {{stored property 'left' of 'Sendable'-conforming struct 'RefPair' has non-sendable type 'Ref'}}
7268
var right: Ref // expected-warning {{stored property 'right' of 'Sendable'-conforming struct 'RefPair' has non-sendable type 'Ref'}}
7369
}
7470

75-
@_moveOnly
76-
enum MaybeRef: Sendable {
71+
enum MaybeRef: ~Copyable, Sendable {
7772
case ref(Ref) // expected-warning {{associated value 'ref' of 'Sendable'-conforming enum 'MaybeRef' has non-sendable type 'Ref'}}
7873
case null
7974
}
8075

81-
@_moveOnly
82-
enum OK_NoncopyableOption<T: Sendable> : Sendable {
76+
enum OK_NoncopyableOption<T: Sendable> : ~Copyable, Sendable {
8377
case some(T)
8478
case none
8579
}
8680

87-
@_moveOnly
88-
enum Wrong_NoncopyableOption<T> : Sendable { // expected-note {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
81+
enum Wrong_NoncopyableOption<T> : ~Copyable, Sendable { // expected-note {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
8982
case some(T) // expected-warning {{associated value 'some' of 'Sendable'-conforming generic enum 'Wrong_NoncopyableOption' has non-sendable type 'T'}}
9083
case none
9184
}
@@ -162,8 +155,7 @@ func tryToDupe(_ fd: __shared FileDescriptor) {
162155
fd.doIllegalThings() // expected-error {{move-only type 'FileDescriptor' cannot be used with generics yet}}
163156
}
164157

165-
@_moveOnly
166-
struct PaperAirplaneFile {
158+
struct PaperAirplaneFile: ~Copyable {
167159
var fd: FileDescriptor
168160
}
169161

0 commit comments

Comments
 (0)