[Strict memory safety] Adjust "unsafe" location for string interpolations

String interpolations can end up being unsafe in the call to
appendInterpolation when it's provided with unsafe types. Move the
location of the proposed "unsafe" out to the string interpolation
itself in these cases, which properly suppresses the warning.

Fixes rdar://151799777.
This commit is contained in:
Doug Gregor
2025-06-02 12:36:36 -07:00
parent e1e9f04398
commit 6ba48f2738
2 changed files with 28 additions and 8 deletions

View File

@@ -376,3 +376,9 @@ protocol CustomAssociated: Associated { }
extension SomeClass: CustomAssociated {
typealias Associated = SomeClassWrapper // expected-note{{unsafe type 'SomeClass.Associated' (aka 'SomeClassWrapper') cannot satisfy safe associated type 'Associated'}}
}
func testInterpolation(ptr: UnsafePointer<Int>) {
_ = "Hello \(unsafe ptr)" // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{7-7=unsafe }}
// expected-note@-1{{reference to unsafe type 'UnsafePointer<Int>'}}
// expected-note@-2{{argument #0 in call to instance method 'appendInterpolation' has unsafe type 'UnsafePointer<Int>'}}
}