mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SE-0458] Drop "unsafe" effect for for..in loop in inlined code in interfaces
Only compilers can't handle it, so drop it for now.
This commit is contained in:
@@ -552,6 +552,10 @@ fileprivate class RemoveUnsafeExprSyntaxRewriter: SyntaxRewriter {
|
||||
override func visit(_ node: UnsafeExprSyntax) -> ExprSyntax {
|
||||
return node.expression.with(\.leadingTrivia, node.leadingTrivia)
|
||||
}
|
||||
|
||||
override func visit(_ node: ForStmtSyntax) -> StmtSyntax {
|
||||
return StmtSyntax(node.with(\.unsafeKeyword, nil))
|
||||
}
|
||||
}
|
||||
|
||||
extension SyntaxProtocol {
|
||||
|
||||
@@ -9,10 +9,21 @@
|
||||
// CHECK: #endif
|
||||
@unsafe public func getIntUnsafely() -> Int { 0 }
|
||||
|
||||
public struct UnsafeIterator: @unsafe IteratorProtocol {
|
||||
@unsafe public mutating func next() -> Int? { nil }
|
||||
}
|
||||
|
||||
public struct SequenceWithUnsafeIterator: Sequence {
|
||||
public init() { }
|
||||
public func makeIterator() -> UnsafeIterator { UnsafeIterator() }
|
||||
}
|
||||
|
||||
// CHECK: @inlinable public func useUnsafeCode()
|
||||
@inlinable public func useUnsafeCode() {
|
||||
// CHECK-NOT: unsafe
|
||||
print( unsafe getIntUnsafely())
|
||||
|
||||
for unsafe _ in SequenceWithUnsafeIterator() { }
|
||||
}
|
||||
|
||||
// CHECK: public protocol P
|
||||
|
||||
Reference in New Issue
Block a user