mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Rename "Unsafe" diagnostic group to "StrictMemorySafety"
This lines up with the feature name and is more consistent. Thank you, Anthony, for the suggestion.
This commit is contained in:
@@ -91,9 +91,9 @@ func testUnsafeAsSequenceForEach() {
|
||||
|
||||
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{12-12=unsafe }}
|
||||
for _ in uas { } // expected-note{{conformance}}
|
||||
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{7-7=unsafe }}
|
||||
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{7-7=unsafe }}
|
||||
|
||||
for _ in unsafe uas { } // expected-warning{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{7-7=unsafe }}
|
||||
for _ in unsafe uas { } // expected-warning{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{7-7=unsafe }}
|
||||
|
||||
for unsafe _ in unsafe uas { } // okay
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class NotSafeSubclass: NotSafe {
|
||||
_ = NotSafe[ns]
|
||||
NotSafe.doStatically(NotSafe.self)
|
||||
|
||||
ns.stillUnsafe() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}
|
||||
ns.stillUnsafe() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
|
||||
// expected-note@-1{{reference to parameter 'ns' involves unsafe type 'NotSafe'}}
|
||||
// expected-note@-2{{reference to unsafe instance method 'stillUnsafe()'}}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class C {
|
||||
|
||||
class D1: C { // expected-note{{make class 'D1' @unsafe to allow unsafe overrides of safe superclass methods}}{{1-1=@unsafe }}
|
||||
@unsafe
|
||||
override func method() { } // expected-warning{{override of safe instance method with unsafe instance method [Unsafe]}}
|
||||
override func method() { } // expected-warning{{override of safe instance method with unsafe instance method [StrictMemorySafety]}}
|
||||
}
|
||||
|
||||
@unsafe class D2: C {
|
||||
@@ -34,7 +34,7 @@ protocol P {
|
||||
}
|
||||
|
||||
struct S1: P {
|
||||
// expected-warning@-1{{conformance of 'S1' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [Unsafe]}}{{12-12=@unsafe }}
|
||||
// expected-warning@-1{{conformance of 'S1' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{12-12=@unsafe }}
|
||||
@unsafe
|
||||
func protoMethod() { } // expected-note{{unsafe instance method 'protoMethod()' cannot satisfy safe requirement}}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ struct S2: P {
|
||||
struct S3 { }
|
||||
|
||||
extension S3: P {
|
||||
// expected-warning@-1{{conformance of 'S3' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [Unsafe]}}{{15-15=@unsafe }}
|
||||
// expected-warning@-1{{conformance of 'S3' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{15-15=@unsafe }}
|
||||
@unsafe
|
||||
func protoMethod() { } // expected-note{{unsafe instance method 'protoMethod()' cannot satisfy safe requirement}}
|
||||
}
|
||||
@@ -116,12 +116,12 @@ extension UnsafeOuter {
|
||||
var yieldUnsafe: Int {
|
||||
_read {
|
||||
@unsafe let x = 5
|
||||
yield x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}
|
||||
yield x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
|
||||
// expected-note@-1{{reference to unsafe let 'x'}}
|
||||
}
|
||||
_modify {
|
||||
@unsafe var x = 5
|
||||
yield &x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}
|
||||
yield &x // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
|
||||
// expected-note@-1{{reference to unsafe var 'x'}}
|
||||
}
|
||||
}
|
||||
@@ -142,9 +142,9 @@ struct UnsafeSequence: @unsafe IteratorProtocol, @unsafe Sequence {
|
||||
}
|
||||
|
||||
func forEachLoop(us: UnsafeSequence) {
|
||||
for _ in us { } // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{12-12=unsafe }}
|
||||
for _ in us { } // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{12-12=unsafe }}
|
||||
// expected-note@-1{{@unsafe conformance of 'UnsafeSequence' to protocol 'Sequence' involves unsafe code}}
|
||||
// expected-warning@-2{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}
|
||||
// expected-warning@-2{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
|
||||
for _ in unsafe us { }
|
||||
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}
|
||||
// expected-warning@-1{{for-in loop uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ protocol P {
|
||||
@unsafe func g()
|
||||
}
|
||||
|
||||
struct XP: P { // expected-warning{{conformance of 'XP' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [Unsafe]}}{{12-12=@unsafe }}
|
||||
struct XP: P { // expected-warning{{conformance of 'XP' to protocol 'P' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{12-12=@unsafe }}
|
||||
@unsafe func f() { } // expected-note{{unsafe instance method 'f()' cannot satisfy safe requirement}}
|
||||
@unsafe func g() { }
|
||||
}
|
||||
@@ -30,7 +30,7 @@ protocol Ptrable2 {
|
||||
}
|
||||
|
||||
extension HasAPointerType: Ptrable2 { } // expected-note{{unsafe type 'HasAPointerType.Ptr' (aka 'PointerType') cannot satisfy safe associated type 'Ptr'}}
|
||||
// expected-warning@-1{{conformance of 'HasAPointerType' to protocol 'Ptrable2' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [Unsafe]}}{{28-28=@unsafe }}
|
||||
// expected-warning@-1{{conformance of 'HasAPointerType' to protocol 'Ptrable2' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{28-28=@unsafe }}
|
||||
|
||||
struct UnsafeXP: @unsafe P {
|
||||
@unsafe func f() { }
|
||||
@@ -44,7 +44,7 @@ protocol MultiP {
|
||||
|
||||
struct ConformsToMultiP { }
|
||||
|
||||
// expected-warning@+1{{conformance of 'ConformsToMultiP' to protocol 'MultiP' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [Unsafe]}}{{29-29=@unsafe }}
|
||||
// expected-warning@+1{{conformance of 'ConformsToMultiP' to protocol 'MultiP' involves unsafe code; use '@unsafe' to indicate that the conformance is not memory-safe [StrictMemorySafety]}}{{29-29=@unsafe }}
|
||||
extension ConformsToMultiP: MultiP {
|
||||
// expected-note@-1{{unsafe type 'UnsafeSuper' cannot satisfy safe associated type 'Ptr'}}
|
||||
@unsafe func f() -> UnsafeSuper {
|
||||
@@ -74,7 +74,7 @@ class Super {
|
||||
}
|
||||
|
||||
class Sub: Super { // expected-note{{make class 'Sub' @unsafe to allow unsafe overrides of safe superclass methods}}{{1-1=@unsafe }}
|
||||
@unsafe override func f() { } // expected-warning{{override of safe instance method with unsafe instance method [Unsafe]}}
|
||||
@unsafe override func f() { } // expected-warning{{override of safe instance method with unsafe instance method [StrictMemorySafety]}}
|
||||
@unsafe override func g() { }
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class ExclusivityChecking {
|
||||
func f() { }
|
||||
};
|
||||
|
||||
// expected-warning@+1{{class 'UnsafeSub' has superclass involving unsafe type 'UnsafeSuper' [Unsafe]}}{{1-1=@unsafe }}
|
||||
// expected-warning@+1{{class 'UnsafeSub' has superclass involving unsafe type 'UnsafeSuper' [StrictMemorySafety]}}{{1-1=@unsafe }}
|
||||
class UnsafeSub: UnsafeSuper { }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -129,13 +129,13 @@ struct BufferThingy<T> {
|
||||
}
|
||||
|
||||
func testConstruction() {
|
||||
let _ = BufferThingy<Int>(count: 17) // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{11-11=unsafe }}
|
||||
let _ = BufferThingy<Int>(count: 17) // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{11-11=unsafe }}
|
||||
// expected-note@-1{{reference to unsafe initializer 'init(count:)'}}
|
||||
}
|
||||
|
||||
func testRHS(b: Bool, x: Int) {
|
||||
@unsafe let limit = 17
|
||||
if b && x > limit { // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [Unsafe]}}{{6-6=unsafe }}
|
||||
if b && x > limit { // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}{{6-6=unsafe }}
|
||||
// expected-note@-1{{reference to unsafe let 'limit'}}
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ typealias SuperUnsafe = UnsafeSuper
|
||||
|
||||
@unsafe typealias SuperUnsafe2 = UnsafeSuper
|
||||
|
||||
// expected-warning@+3{{enum 'HasUnsafeThings' has storage involving unsafe types [Unsafe]}}
|
||||
// expected-warning@+3{{enum 'HasUnsafeThings' has storage involving unsafe types [StrictMemorySafety]}}
|
||||
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}{{1-1=@unsafe }}
|
||||
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}{{1-1=@safe }}
|
||||
enum HasUnsafeThings {
|
||||
@@ -181,7 +181,7 @@ case one(UnsafeSuper) // expected-note{{enum case 'one' involves unsafe type 'Un
|
||||
case two(UnsafeSuper) // expected-note{{enum case 'two' involves unsafe type 'UnsafeSuper'}}
|
||||
}
|
||||
|
||||
// expected-warning@+3{{class 'ClassWithUnsafeStorage' has storage involving unsafe types [Unsafe]}}
|
||||
// expected-warning@+3{{class 'ClassWithUnsafeStorage' has storage involving unsafe types [StrictMemorySafety]}}
|
||||
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}{{1-1=@unsafe }}
|
||||
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}{{1-1=@safe }}
|
||||
class ClassWithUnsafeStorage {
|
||||
|
||||
Reference in New Issue
Block a user