Always emit "unsafe does not cover any unsafe constructs" warning

Check for unsafe constructs in all modes, so that we can emit the
"unsafe does not cover any unsafe constructs" warning consistently.
One does not need to write "unsafe" outside of strict memory safety
mode, but if you do... it needs to cover unsafe behavior.
This commit is contained in:
Doug Gregor
2025-04-25 23:22:09 -07:00
parent 02e1d11896
commit 1b94c3b3d6
7 changed files with 9 additions and 23 deletions

View File

@@ -361,11 +361,11 @@ func testSequenceExpr() async throws(Never) {
_ = unsafe await try! getIntAsync() + getIntAsync()
// expected-warning@-1 {{'try' must precede 'await'}}
// expected-warning@-2{{no unsafe operations occur within 'unsafe' expression}}
_ = try unsafe await try! getIntAsync() + getIntAsync()
// expected-warning@-1 {{'try' must precede 'await'}}
// expected-warning@-2 {{no calls to throwing functions occur within 'try' expression}}
// expected-warning@-3{{no unsafe operations occur within 'unsafe' expression}}
try _ = (try! getInt()) + getInt()
// expected-error@-1:29 {{thrown expression type 'any Error' cannot be converted to error type 'Never'}}