mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Find all the usages of `--enable-experimental-feature` or `--enable-upcoming-feature` in the tests and replace some of the `REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which should correctly apply to depending on the asserts/noasserts mode of the toolchain for each feature. Remove some comments that talked about enabling asserts since they don't apply anymore (but I might had miss some). All this was done with an automated script, so some formatting weirdness might happen, but I hope I fixed most of those. There might be some tests that were `REQUIRES: asserts` that might run in `noasserts` toolchains now. This will normally be because their feature went from experimental to upcoming/base and the tests were not updated.
73 lines
2.1 KiB
Swift
73 lines
2.1 KiB
Swift
// RUN: %target-swift-frontend %s -sil-verify-all -verify -emit-sil -enable-experimental-feature MoveOnlyPartialReinitialization
|
|
|
|
// REQUIRES: swift_feature_MoveOnlyPartialReinitialization
|
|
|
|
/// MARK: types
|
|
|
|
struct FileDescriptor: ~Copyable { let fd: Int = 0 }
|
|
|
|
struct Wrap<T: ~Copyable>: ~Copyable {
|
|
var item: T
|
|
init(_ t: consuming T) { self.item = t }
|
|
}
|
|
extension Wrap: Copyable where T: Copyable {}
|
|
|
|
/// MARK: utilities
|
|
|
|
func borrowAny<T: ~Copyable>(_ t: borrowing T) {}
|
|
|
|
/// MARK: tests
|
|
|
|
func barebones() {
|
|
let nc = FileDescriptor() // expected-error {{'nc' consumed more than once}}
|
|
borrowAny(nc)
|
|
let _ = nc // expected-note {{consumed}}
|
|
let _ = nc // expected-note {{consumed}}
|
|
|
|
let cpWrap = Wrap(100)
|
|
borrowAny(cpWrap)
|
|
let _ = cpWrap
|
|
let _ = cpWrap
|
|
|
|
let ncWrap = Wrap(FileDescriptor()) // expected-error {{'ncWrap' consumed more than once}}
|
|
borrowAny(ncWrap)
|
|
let _ = ncWrap // expected-note {{consumed}}
|
|
let _ = ncWrap // expected-note {{consumed}}
|
|
}
|
|
|
|
func test1<T: ~Copyable>(_ t: consuming T, // expected-error {{'t' consumed more than once}}
|
|
// expected-error@-1 {{'t' used after consume}}
|
|
_ borrowArg: borrowing T) -> Wrap<T> {
|
|
// expected-error@-1 {{'borrowArg' is borrowed and cannot be consumed}}
|
|
borrowAny(t)
|
|
borrowAny(borrowArg)
|
|
|
|
let wrap1 = Wrap(t) // expected-note {{consumed}}
|
|
let _ = Wrap(t) // expected-note 2{{consumed}}
|
|
|
|
let _ = Wrap(borrowArg) // expected-note {{consumed}}
|
|
|
|
borrowAny(t) // expected-note {{used}}
|
|
borrowAny(borrowArg)
|
|
|
|
return wrap1
|
|
}
|
|
|
|
func testWrap<T: ~Copyable>(_ x: borrowing Wrap<T>,
|
|
// expected-error@-1 {{'x' is borrowed and cannot be consumed}}
|
|
_ y: consuming Wrap<T>,
|
|
_ new: () -> T) -> T {
|
|
_ = x.item // expected-note {{consumed}}
|
|
|
|
// expected-error@+1 {{'result' consumed more than once}}
|
|
let result = { (v: inout Wrap<T>) -> T in
|
|
let result = v.item
|
|
v.item = new()
|
|
return result
|
|
}(&y)
|
|
|
|
let _ = result // expected-note {{consumed}}
|
|
|
|
return result // expected-note {{consumed}}
|
|
}
|