Skip to content

Fix a move-checker diagnostic message (textual change) #82862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt8> {
@_lifetime(borrow self)
borrowing get {
let span: Span<UInt8> = Span(_bytes: self.buffer.bytes)
return span
}
}
}

// Test a borrowed dependency on an address
@_lifetime(immortal)
public func testGenericDep<T: ~Escapable>(type: T.Type) -> T {
Expand Down Expand Up @@ -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}}
}