Skip to content

Commit 22eecac

Browse files
committed
Adopt unsafe annotations throughout the standard library
1 parent 50d3913 commit 22eecac

File tree

127 files changed

+4082
-3946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4082
-3946
lines changed

stdlib/public/core/ASCII.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension Unicode.ASCII: Unicode.Encoding {
6161
}
6262
else if _fastPath(FromEncoding.self == UTF8.self) {
6363
let c = _identityCast(content, to: UTF8.EncodedScalar.self)
64-
let first = c.first.unsafelyUnwrapped
64+
let first = unsafe c.first.unsafelyUnwrapped
6565
guard (first < 0x80) else { return nil }
6666
return EncodedScalar(CodeUnit(first))
6767
}

stdlib/public/core/AnyHashable.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal struct _ConcreteHashableBox<Base: Hashable>: _AnyHashableBox {
103103
internal
104104
func _downCastConditional<T>(into result: UnsafeMutablePointer<T>) -> Bool {
105105
guard let value = _baseHashable as? T else { return false }
106-
result.initialize(to: value)
106+
unsafe result.initialize(to: value)
107107
return true
108108
}
109109
}
@@ -165,8 +165,8 @@ public struct AnyHashable {
165165
}
166166

167167
self.init(_box: _ConcreteHashableBox(false)) // Dummy value
168-
_withUnprotectedUnsafeMutablePointer(to: &self) {
169-
_makeAnyHashableUpcastingToHashableBaseType(
168+
unsafe _withUnprotectedUnsafeMutablePointer(to: &self) {
169+
unsafe _makeAnyHashableUpcastingToHashableBaseType(
170170
base,
171171
storingResultInto: $0)
172172
}
@@ -197,13 +197,13 @@ public struct AnyHashable {
197197
internal
198198
func _downCastConditional<T>(into result: UnsafeMutablePointer<T>) -> Bool {
199199
// Attempt the downcast.
200-
if _box._downCastConditional(into: result) { return true }
200+
if unsafe _box._downCastConditional(into: result) { return true }
201201

202202
#if _runtime(_ObjC)
203203
// Bridge to Objective-C and then attempt the cast from there.
204204
// FIXME: This should also work without the Objective-C runtime.
205205
if let value = _bridgeAnythingToObjectiveC(_box._base) as? T {
206-
result.initialize(to: value)
206+
unsafe result.initialize(to: value)
207207
return true
208208
}
209209
#endif
@@ -308,7 +308,7 @@ internal func _makeAnyHashableUsingDefaultRepresentation<H: Hashable>(
308308
of value: H,
309309
storingResultInto result: UnsafeMutablePointer<AnyHashable>
310310
) {
311-
result.pointee = AnyHashable(_usingDefaultRepresentationOf: value)
311+
unsafe result.pointee = AnyHashable(_usingDefaultRepresentationOf: value)
312312
}
313313

314314
/// Provided by AnyHashable.cpp.
@@ -333,7 +333,7 @@ internal func _convertToAnyHashableIndirect<H: Hashable>(
333333
_ value: H,
334334
_ target: UnsafeMutablePointer<AnyHashable>
335335
) {
336-
target.initialize(to: AnyHashable(value))
336+
unsafe target.initialize(to: AnyHashable(value))
337337
}
338338

339339
/// Called by the casting machinery.
@@ -343,5 +343,5 @@ internal func _anyHashableDownCastConditionalIndirect<T>(
343343
_ value: UnsafePointer<AnyHashable>,
344344
_ target: UnsafeMutablePointer<T>
345345
) -> Bool {
346-
return value.pointee._downCastConditional(into: target)
346+
return unsafe value.pointee._downCastConditional(into: target)
347347
}

0 commit comments

Comments
 (0)