[Strict memory safety] Treat the implicit call to a 'defer' function as implicitly 'unsafe'

This eliminates stray warnings.
This commit is contained in:
Doug Gregor
2025-04-19 21:57:12 -07:00
parent 457eb4cc64
commit b7d41a55a5
2 changed files with 40 additions and 0 deletions

View File

@@ -293,3 +293,18 @@ struct UnsafeContainingUnspecified {
let a = unsafe x.getA()
_ = a
}
extension Slice {
// Make sure we aren't diagnosing the 'defer' as unsafe.
public func withContiguousMutableStorageIfAvailable<R, Element>(
_ body: (_ buffer: inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R? where Base == UnsafeMutableBufferPointer<Element> {
try unsafe base.withContiguousStorageIfAvailable { buffer in
let start = unsafe base.baseAddress?.advanced(by: startIndex)
var slice = unsafe UnsafeMutableBufferPointer(start: start, count: count)
defer {
}
return try unsafe body(&slice)
}
}
}