From 49b9d9725ef1dc20d01970fa9e9334e1d16c19ca Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Tue, 26 Nov 2024 16:02:36 +0000 Subject: [PATCH] fix remaining warnings & enable -warnings-as-errors in CI (#3000) ### Motivation: Warnings are annoying. ### Modifications: - Remove unnecessary use of `Foundation.Thread` which isn't Sendable. - Remove now unnecessary `@retroactive`s. - Enable `-warnings-as-errors` in CI ### Result: - Warnings can't sneak in as easily anymore - No more warnings left in `swift-nio` ``` $ rm -rf .build/arm64-apple-macosx/ && swift build --build-tests -Xswiftc -warnings-as-errors > /dev/null echo $? $ echo $? 0 ``` Co-authored-by: Cory Benfield --- .github/workflows/main.yml | 4 +-- .../ByteBuffer-foundation.swift | 6 ---- .../NIOPosixTests/EchoServerClientTest.swift | 2 +- Tests/NIOPosixTests/NIOThreadPoolTest.swift | 29 +++++++------------ Tests/NIOPosixTests/SALEventLoopTests.swift | 6 +--- Tests/NIOPosixTests/TestUtils.swift | 4 +-- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 13420a4d8..f6fd16711 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,8 +14,8 @@ jobs: with: linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" - linux_6_0_arguments_override: "--explicit-target-dependency-import-check error" - linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_nightly_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" cxx-interop: diff --git a/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift b/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift index cf1a25830..c4240d4ed 100644 --- a/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift +++ b/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift @@ -377,15 +377,9 @@ extension ByteBufferAllocator { } // MARK: - Conformances -#if compiler(>=6.0) -extension ByteBufferView: @retroactive ContiguousBytes {} -extension ByteBufferView: @retroactive DataProtocol {} -extension ByteBufferView: @retroactive MutableDataProtocol {} -#else extension ByteBufferView: ContiguousBytes {} extension ByteBufferView: DataProtocol {} extension ByteBufferView: MutableDataProtocol {} -#endif extension ByteBufferView { public typealias Regions = CollectionOfOne diff --git a/Tests/NIOPosixTests/EchoServerClientTest.swift b/Tests/NIOPosixTests/EchoServerClientTest.swift index 678f6da80..9675e1946 100644 --- a/Tests/NIOPosixTests/EchoServerClientTest.swift +++ b/Tests/NIOPosixTests/EchoServerClientTest.swift @@ -224,7 +224,7 @@ class EchoServerClientTest: XCTestCase { try withTemporaryUnixDomainSocketPathName { udsPath in // Bootstrap should not overwrite an existing file unless it is a socket - FileManager.default.createFile(atPath: udsPath, contents: nil, attributes: nil) + _ = FileManager.default.createFile(atPath: udsPath, contents: nil, attributes: nil) let bootstrap = ServerBootstrap(group: group) XCTAssertThrowsError( diff --git a/Tests/NIOPosixTests/NIOThreadPoolTest.swift b/Tests/NIOPosixTests/NIOThreadPoolTest.swift index ed39352df..21eda2b44 100644 --- a/Tests/NIOPosixTests/NIOThreadPoolTest.swift +++ b/Tests/NIOPosixTests/NIOThreadPoolTest.swift @@ -78,18 +78,15 @@ class NIOThreadPoolTest: XCTestCase { // The lock here is arguably redundant with the dispatchgroup, but let's make // this test thread-safe even if I screw up. - let lock = NIOLock() - let threadOne: NIOLockedValueBox = NIOLockedValueBox(Thread?.none) - let threadTwo: NIOLockedValueBox = NIOLockedValueBox(Thread?.none) + let threadOne: NIOLockedValueBox = NIOLockedValueBox(NIOThread?.none) + let threadTwo: NIOLockedValueBox = NIOLockedValueBox(NIOThread?.none) completionGroup.enter() pool.submit { s in precondition(s == .active) - lock.withLock { () -> Void in - threadOne.withLockedValue { threadOne in - XCTAssertEqual(threadOne, nil) - threadOne = Thread.current - } + threadOne.withLockedValue { threadOne in + XCTAssertEqual(threadOne, nil) + threadOne = NIOThread.current } completionGroup.leave() } @@ -99,22 +96,18 @@ class NIOThreadPoolTest: XCTestCase { completionGroup.enter() pool.submit { s in precondition(s == .active) - lock.withLock { () -> Void in - threadTwo.withLockedValue { threadTwo in - XCTAssertEqual(threadTwo, nil) - threadTwo = Thread.current - } + threadTwo.withLockedValue { threadTwo in + XCTAssertEqual(threadTwo, nil) + threadTwo = NIOThread.current } completionGroup.leave() } completionGroup.wait() - lock.withLock { () -> Void in - XCTAssertNotNil(threadOne) - XCTAssertNotNil(threadTwo) - XCTAssertEqual(threadOne.withLockedValue { $0 }, threadTwo.withLockedValue { $0 }) - } + XCTAssertNotNil(threadOne.withLockedValue { $0 }) + XCTAssertNotNil(threadTwo.withLockedValue { $0 }) + XCTAssertEqual(threadOne.withLockedValue { $0 }, threadTwo.withLockedValue { $0 }) } func testAsyncThreadPool() async throws { diff --git a/Tests/NIOPosixTests/SALEventLoopTests.swift b/Tests/NIOPosixTests/SALEventLoopTests.swift index 6cc81f5c8..ad3656475 100644 --- a/Tests/NIOPosixTests/SALEventLoopTests.swift +++ b/Tests/NIOPosixTests/SALEventLoopTests.swift @@ -59,16 +59,12 @@ final class SALEventLoopTests: XCTestCase, SALTest { } // Now execute 10 tasks. - var i = 0 for _ in 0..<10 { - thisLoop.execute { - i &+= 1 - } + thisLoop.execute {} } // Now enqueue a "last" task. thisLoop.execute { - i &+= 1 promise.succeed(()) } diff --git a/Tests/NIOPosixTests/TestUtils.swift b/Tests/NIOPosixTests/TestUtils.swift index c239a09c8..ab5a11891 100644 --- a/Tests/NIOPosixTests/TestUtils.swift +++ b/Tests/NIOPosixTests/TestUtils.swift @@ -127,7 +127,7 @@ func withTemporaryUnixDomainSocketPathName( shortEnoughPath = path restoreSavedCWD = false } catch SocketAddressError.unixDomainSocketPathTooLong { - FileManager.default.changeCurrentDirectoryPath( + _ = FileManager.default.changeCurrentDirectoryPath( URL(fileURLWithPath: path).deletingLastPathComponent().absoluteString ) shortEnoughPath = URL(fileURLWithPath: path).lastPathComponent @@ -141,7 +141,7 @@ func withTemporaryUnixDomainSocketPathName( try? FileManager.default.removeItem(atPath: path) } if restoreSavedCWD { - FileManager.default.changeCurrentDirectoryPath(saveCurrentDirectory) + _ = FileManager.default.changeCurrentDirectoryPath(saveCurrentDirectory) } } return try body(shortEnoughPath)