Skip to content

Commit 5fcf371

Browse files
authored
Merge pull request #82864 from atrick/62-moveonly-diag
[6.2] Fix a move-checker diagnostic message (textual change)
2 parents 6ece29f + 4c115f1 commit 5fcf371

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none,
840840
"parameter",
841841
(StringRef))
842842
ERROR(sil_movechecking_capture_consumed, none,
843-
"noncopyable '%0' cannot be consumed when captured by an escaping closure", (StringRef))
843+
"noncopyable '%0' cannot be consumed when captured by an escaping closure or borrowed by a non-Escapable type",
844+
(StringRef))
844845
ERROR(sil_movechecking_not_reinitialized_before_end_of_function, none,
845846
"missing reinitialization of %select{inout parameter|closure capture}1 '%0' "
846847
"after consume", (StringRef, bool))

test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ struct TestDeinitCallsAddressor: ~Copyable, ~Escapable {
121121
}
122122
}
123123

124+
struct NCBuffer: ~Copyable {
125+
fileprivate let buffer: UnsafeMutableRawBufferPointer
126+
127+
public init() {
128+
let ptr = UnsafeMutableRawPointer.init(bitPattern: 0)
129+
self.buffer = UnsafeMutableRawBufferPointer(start: ptr, count: 0)
130+
}
131+
132+
public var bytes: Span<UInt8> {
133+
@_lifetime(borrow self)
134+
borrowing get {
135+
let span: Span<UInt8> = Span(_bytes: self.buffer.bytes)
136+
return span
137+
}
138+
}
139+
}
140+
124141
// Test a borrowed dependency on an address
125142
@_lifetime(immortal)
126143
public func testGenericDep<T: ~Escapable>(type: T.Type) -> T {
@@ -287,3 +304,15 @@ func testSpanMayThrow(buffer: inout [Int]) {
287304
let bufferSpan = buffer.mutableSpan
288305
try! mutableSpanMayThrow(bufferSpan)
289306
}
307+
308+
// =============================================================================
309+
// Dependence on non-Copyable values
310+
// =============================================================================
311+
312+
@_lifetime(immortal)
313+
func dependOnNonCopyable() -> NCBuffer {
314+
let buffer = NCBuffer()
315+
let count = buffer.bytes.count
316+
_ = count
317+
return buffer // expected-error {{noncopyable 'buffer' cannot be consumed when captured by an escaping closure or borrowed by a non-Escapable type}}
318+
}

0 commit comments

Comments
 (0)