Skip to content

Commit fb31e5a

Browse files
committed
add test for warnings emitted when missing consuming attribute
1 parent 854be10 commit fb31e5a

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 ExecutorJob) {
48+
public init(_ job: __owned ExecutorJob) { // 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
@@ -78,3 +78,15 @@ final class NewExecutor: SerialExecutor {
7878
UnownedSerialExecutor(ordinary: self)
7979
}
8080
}
81+
82+
// Good impl, but missing the ownership keyword
83+
final class MissingOwnership: SerialExecutor {
84+
func enqueue(_ job: ExecutorJob) {} // expected-error{{noncopyable parameter must specify its ownership}}
85+
// expected-note@-1{{add 'borrowing' for an immutable reference}}
86+
// expected-note@-2{{add 'inout' for a mutable reference}}
87+
// expected-note@-3{{add 'consuming' to take the value from the caller}}
88+
89+
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
90+
UnownedSerialExecutor(ordinary: self)
91+
}
92+
}

0 commit comments

Comments
 (0)