-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
According to SE-377:
We propose new
borrowingandconsumingparameter modifiers to allow developers to explicitly choose the ownership convention that a function uses to receive immutable parameters. Applying one of these modifiers to a parameter causes that parameter binding to no longer be implicitly copyable, and potential copies need to be marked with the new copy x operator.
In the reproduction test case, the compiler performs a copy of a parameter marked as borrowing without the developer having to use the copy operator.
(there is a related bug, which I will file separately, about this crashing the compiler if Foo<T> is ~Copyable)
Reproduction
struct Foo<T> {}
func huh<T>(_ source: borrowing Foo<T>) {
let process: (borrowing Foo<T>) -> () -> Void = {
s in { _ = consume s } // This should not be valid!
}
process(source)()
}Expected behavior
Expect the compiler to reject the reproduction test case. It is not possible to consume a borrow!
Environment
Swift version 6.0-dev (LLVM 73a346c9caf32cc, Swift 3e21fc6)
Target: x86_64-unknown-linux-gnu
Additional information
No response