Skip to content

Commit 201d31b

Browse files
committed
add test for warnings emitted when missing consuming attribute
1 parent 920f338 commit 201d31b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct UnownedJob: Sendable {
4545
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4646
/// Create an `UnownedJob` whose lifetime must be managed carefully until it is run exactly once.
4747
@available(SwiftStdlib 5.9, *)
48-
public init(_ job: __owned Job) {
48+
public init(_ job: __owned Job) { // must remain '__owned' in order to not break ABI
4949
self.context = job.context
5050
}
5151
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

test/Concurrency/custom_executor_enqueue_impls.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ final class NewExecutor: SerialExecutor {
5151
UnownedSerialExecutor(ordinary: self)
5252
}
5353
}
54+
55+
// Good impl, but missing the ownership keyword
56+
final class MissingOwnership: SerialExecutor {
57+
func enqueue(_ job: ExecutorJob) {} // expected-error{{noncopyable parameter must specify its ownership}}
58+
// expected-note@-1{{add 'borrowing' for an immutable reference}}
59+
// expected-note@-2{{add 'inout' for a mutable reference}}
60+
// expected-note@-3{{add 'consuming' to take the value from the caller}}
61+
62+
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
63+
UnownedSerialExecutor(ordinary: self)
64+
}
65+
}

0 commit comments

Comments
 (0)