diff --git a/include/swift/AST/DiagnosticsSIL.def b/include/swift/AST/DiagnosticsSIL.def index 34b1577b3e3a8..d4ab8a34ad64b 100644 --- a/include/swift/AST/DiagnosticsSIL.def +++ b/include/swift/AST/DiagnosticsSIL.def @@ -857,7 +857,8 @@ ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none, "parameter", (StringRef)) ERROR(sil_movechecking_capture_consumed, none, - "noncopyable '%0' cannot be consumed when captured by an escaping closure", (StringRef)) + "noncopyable '%0' cannot be consumed when captured by an escaping closure or borrowed by a non-Escapable type", + (StringRef)) ERROR(sil_movechecking_not_reinitialized_before_end_of_function, none, "missing reinitialization of %select{inout parameter|closure capture}1 '%0' " "after consume", (StringRef, bool)) diff --git a/test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift b/test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift index 659e7f4d66d3b..917aecb9e1330 100644 --- a/test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift +++ b/test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift @@ -121,6 +121,23 @@ struct TestDeinitCallsAddressor: ~Copyable, ~Escapable { } } +struct NCBuffer: ~Copyable { + fileprivate let buffer: UnsafeMutableRawBufferPointer + + public init() { + let ptr = UnsafeMutableRawPointer.init(bitPattern: 0) + self.buffer = UnsafeMutableRawBufferPointer(start: ptr, count: 0) + } + + public var bytes: Span { + @_lifetime(borrow self) + borrowing get { + let span: Span = Span(_bytes: self.buffer.bytes) + return span + } + } +} + // Test a borrowed dependency on an address @_lifetime(immortal) public func testGenericDep(type: T.Type) -> T { @@ -287,3 +304,15 @@ func testSpanMayThrow(buffer: inout [Int]) { let bufferSpan = buffer.mutableSpan try! mutableSpanMayThrow(bufferSpan) } + +// ============================================================================= +// Dependence on non-Copyable values +// ============================================================================= + +@_lifetime(immortal) +func dependOnNonCopyable() -> NCBuffer { + let buffer = NCBuffer() + let count = buffer.bytes.count + _ = count + return buffer // expected-error {{noncopyable 'buffer' cannot be consumed when captured by an escaping closure or borrowed by a non-Escapable type}} +}