Skip to content

Commit 6035562

Browse files
Use new shorthand syntax for unwrapping optionals (#6329)
1 parent aa6f358 commit 6035562

File tree

85 files changed

+222
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+222
-222
lines changed

Sources/Basics/AuthorizationProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWri
9797
let contents = try? self.fileSystem.readFileContents(self.path).contents
9898
try self.fileSystem.writeFileContents(self.path) { stream in
9999
// Write existing contents
100-
if let contents = contents, !contents.isEmpty {
100+
if let contents, !contents.isEmpty {
101101
stream.write(contents)
102102
stream.write("\n")
103103
}

Sources/Basics/Concurrency/SendableBox.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public actor SendableBox<Value: Sendable> {
2525

2626
extension SendableBox where Value == Int {
2727
func increment() {
28-
if let value = self.value {
28+
if let value {
2929
self.value = value + 1
3030
}
3131
}
3232

3333
func decrement() {
34-
if let value = self.value {
34+
if let value {
3535
self.value = value - 1
3636
}
3737
}

Sources/Basics/FileSystem/VirtualFileSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public class VirtualFileSystem: FileSystem {
215215
switch node {
216216
case .directory(_, _, _): throw Errors.notAFile(path: path)
217217
case .file(_, _, _, let contents):
218-
if let contents = contents {
218+
if let contents {
219219
return ByteString(contents)
220220
} else {
221221
return ""

Sources/Basics/HTTPClient/URLSessionHTTPClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private class DataTaskManager: NSObject, URLSessionDataDelegate {
157157
guard let task = self.tasks.removeValue(forKey: task.taskIdentifier) else {
158158
return
159159
}
160-
if let error = error {
160+
if let error {
161161
task.completionHandler(.failure(error))
162162
} else if let response = task.response {
163163
task.completionHandler(.success(response.response(body: task.buffer)))
@@ -294,7 +294,7 @@ private class DownloadTaskManager: NSObject, URLSessionDownloadDelegate {
294294
}
295295

296296
do {
297-
if let error = error {
297+
if let error {
298298
throw HTTPClientError.downloadError("\(error)")
299299
} else if let error = task.moveFileError {
300300
throw error

Sources/Basics/SQLite.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public final class SQLite {
8787

8888
sqlite3_free(query)
8989

90-
if let err = err {
90+
if let err {
9191
let errorString = String(cString: err)
9292
sqlite3_free(err)
9393
throw StringError(errorString)
@@ -286,7 +286,7 @@ public final class SQLite {
286286
case "database or disk is full":
287287
throw Errors.databaseFull
288288
default:
289-
if let prefix = prefix {
289+
if let prefix {
290290
description = "\(prefix): \(description)"
291291
}
292292
throw StringError(description)
@@ -309,8 +309,8 @@ private func sqlite_callback(
309309
_ columns: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?,
310310
_ columnNames: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?
311311
) -> Int32 {
312-
guard let ctx = ctx else { return 0 }
313-
guard let columnNames = columnNames, let columns = columns else { return 0 }
312+
guard let ctx else { return 0 }
313+
guard let columnNames, let columns else { return 0 }
314314
let numColumns = Int(numColumns)
315315
var result: [SQLite.Column] = []
316316

Sources/Basics/SwiftVersion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct SwiftVersion {
3535
if self.isDevelopment {
3636
result += "-dev"
3737
}
38-
if let buildIdentifier = self.buildIdentifier {
38+
if let buildIdentifier {
3939
result += " (" + buildIdentifier + ")"
4040
}
4141
return result

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public final class ClangTargetBuildDescription {
231231
// Include the path to the resource header unless the arguments are
232232
// being evaluated for a C file. A C file cannot depend on the resource
233233
// accessor header due to it exporting a Foundation type (`NSBundle`).
234-
if let resourceAccessorHeaderFile = self.resourceAccessorHeaderFile, !isC {
234+
if let resourceAccessorHeaderFile, !isC {
235235
args += ["-include", resourceAccessorHeaderFile.pathString]
236236
}
237237

@@ -304,7 +304,7 @@ public final class ClangTargetBuildDescription {
304304
/// Generate the resource bundle accessor, if appropriate.
305305
private func generateResourceAccessor() throws {
306306
// Only generate access when we have a bundle and ObjC files.
307-
guard let bundlePath = self.bundlePath, clangTarget.sources.containsObjcFiles else { return }
307+
guard let bundlePath, clangTarget.sources.containsObjcFiles else { return }
308308

309309
// Compute the basename of the bundle.
310310
let bundleBasename = bundlePath.basename

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public final class SwiftTargetBuildDescription {
240240
self.toolsVersion = toolsVersion
241241
self.buildParameters = buildParameters
242242
// Unless mentioned explicitly, use the target type to determine if this is a test target.
243-
if let testTargetRole = testTargetRole {
243+
if let testTargetRole {
244244
self.testTargetRole = testTargetRole
245245
} else if target.type == .test {
246246
self.testTargetRole = .default
@@ -336,7 +336,7 @@ public final class SwiftTargetBuildDescription {
336336
/// Generate the resource bundle accessor, if appropriate.
337337
private func generateResourceAccessor() throws {
338338
// Do nothing if we're not generating a bundle.
339-
guard let bundlePath = self.bundlePath else { return }
339+
guard let bundlePath else { return }
340340

341341
let mainPathSubstitution: String
342342
if self.buildParameters.triple.isWASI() {

Sources/Build/BuildOperation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
319319
// Compiles a single plugin, emitting its output and throwing an error if it
320320
// fails.
321321
func compilePlugin(_ plugin: PluginDescription) throws {
322-
guard let pluginConfiguration = self.pluginConfiguration else {
322+
guard let pluginConfiguration else {
323323
throw InternalError("unknown plugin script runner")
324324
}
325325
// Compile the plugin, getting back a PluginCompilationResult.
@@ -408,7 +408,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
408408
let buildToolPluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]]
409409
let prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]]
410410
// Invoke any build tool plugins in the graph to generate prebuild commands and build commands.
411-
if let pluginConfiguration = self.pluginConfiguration {
411+
if let pluginConfiguration {
412412
let buildOperationForPluginDependencies = try BuildOperation(buildParameters: self.buildParameters.withDestination(self.buildParameters.hostTriple), cacheBuildManifest: false, packageGraphLoader: { return graph }, additionalFileRules: self.additionalFileRules, pkgConfigDirectories: self.pkgConfigDirectories, outputStream: self.outputStream, logLevel: self.logLevel, fileSystem: self.fileSystem, observabilityScope: self.observabilityScope)
413413
buildToolPluginInvocationResults = try graph.invokeBuildToolPlugins(
414414
outputDir: pluginConfiguration.workDirectory.appending("outputs"),

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ private struct CommandTaskTracker {
916916
let fileNameStartIndex = command.description.index(after: lastDirectorySeparatorIndex)
917917
let fileName = command.description[fileNameStartIndex...]
918918

919-
if let targetName = targetName {
919+
if let targetName {
920920
return "\(action) \(targetName) \(fileName)"
921921
} else {
922922
return "\(action) \(fileName)"

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ extension LLBuildManifestBuilder {
292292

293293
// Check if an explicit pre-build dependency job has already been
294294
// added as a part of this build.
295-
if let uniqueDependencyTracker = uniqueExplicitDependencyTracker,
295+
if let uniqueExplicitDependencyTracker,
296296
job.isExplicitDependencyPreBuildJob
297297
{
298-
if try !uniqueDependencyTracker.registerExplicitDependencyBuildJob(job) {
298+
if try !uniqueExplicitDependencyTracker.registerExplicitDependencyBuildJob(job) {
299299
// This is a duplicate of a previously-seen identical job.
300300
// Skip adding it to the manifest
301301
continue
@@ -619,10 +619,10 @@ extension LLBuildManifestBuilder {
619619
// Depend on the binary for executable targets.
620620
if target.type == .executable {
621621
// FIXME: Optimize.
622-
let _product = try plan.graph.allProducts.first {
622+
let product = try plan.graph.allProducts.first {
623623
try $0.type == .executable && $0.executableTarget == target
624624
}
625-
if let product = _product {
625+
if let product {
626626
guard let planProduct = plan.productMap[product] else {
627627
throw InternalError("unknown product \(product)")
628628
}
@@ -855,8 +855,8 @@ extension LLBuildManifestBuilder {
855855
// Add language standard flag if needed.
856856
if let ext = path.source.extension {
857857
for (standard, validExtensions) in standards {
858-
if let languageStandard = standard, validExtensions.contains(ext) {
859-
args += ["-std=\(languageStandard)"]
858+
if let standard, validExtensions.contains(ext) {
859+
args += ["-std=\(standard)"]
860860
}
861861
}
862862
}

Sources/Commands/PackageTools/ArchiveSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension SwiftPackageTool {
3636
let packageDirectory = try globalOptions.locations.packageDirectory ?? swiftTool.getPackageRoot()
3737

3838
let archivePath: AbsolutePath
39-
if let output = output {
39+
if let output {
4040
archivePath = output
4141
} else {
4242
let graph = try swiftTool.loadPackageGraph()

Sources/Commands/PackageTools/Learn.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension SwiftPackageTool {
3333
.map { try AbsolutePath(validating: $0, relativeTo: directory) }
3434
.filter { fileSystem.isFile($0) }
3535

36-
guard let fileExtension = fileExtension else {
36+
guard let fileExtension else {
3737
return files
3838
}
3939

Sources/Commands/PackageTools/ToolsVersionCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct ToolsVersionCommand: SwiftCommand {
4040

4141
var toolsVersionMode: ToolsVersionMode {
4242
// TODO: enforce exclusivity
43-
if let set = set {
43+
if let set {
4444
return .set(set)
4545
} else if setCurrent {
4646
return .setCurrent

Sources/Commands/Snippets/CardStack.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct CardStack {
5858
}
5959

6060
func askForLineInput(prompt: String?) -> String? {
61-
if let prompt = prompt {
61+
if let prompt {
6262
print(brightBlack { prompt }.terminalString())
6363
}
6464
terminal.write(">>> ", inColor: .green, bold: true)
@@ -99,7 +99,7 @@ struct CardStack {
9999
break askForLine
100100
case let .pop(error):
101101
cards.removeLast()
102-
if let error = error {
102+
if let error {
103103
self.swiftTool.observabilityScope.emit(error)
104104
needsToClearScreen = false
105105
} else {

Sources/Commands/SwiftBuildTool.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ struct BuildToolOptions: ParsableArguments {
4343
func buildSubset(observabilityScope: ObservabilityScope) -> BuildSubset? {
4444
var allSubsets: [BuildSubset] = []
4545

46-
if let productName = product {
47-
allSubsets.append(.product(productName))
46+
if let product {
47+
allSubsets.append(.product(product))
4848
}
4949

50-
if let targetName = target {
51-
allSubsets.append(.target(targetName))
50+
if let target {
51+
allSubsets.append(.target(target))
5252
}
5353

5454
if buildTests {

Sources/Commands/SwiftTestTool.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,13 @@ final class TestRunner {
668668
throw TestError.xctestNotAvailable
669669
}
670670
args = [xctestPath.pathString]
671-
if let xctestArg = xctestArg {
671+
if let xctestArg {
672672
args += ["-XCTest", xctestArg]
673673
}
674674
args += [testPath.pathString]
675675
#else
676676
args += [testPath.description]
677-
if let xctestArg = xctestArg {
677+
if let xctestArg {
678678
args += [xctestArg]
679679
}
680680
#endif

Sources/Commands/Utilities/APIDigester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public struct SwiftAPIDigester {
226226
"-module", module
227227
]
228228
args.append(contentsOf: try buildPlan.createAPIToolCommonArgs(includeLibrarySearchPaths: false))
229-
if let breakageAllowlistPath = breakageAllowlistPath {
229+
if let breakageAllowlistPath {
230230
args.append(contentsOf: ["-breakage-allowlist-path", breakageAllowlistPath.pathString])
231231
}
232232

Sources/Commands/Utilities/DescribedPackage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public struct PlainTextEncoder {
350350
private mutating func emit(_ key: CodingKey, _ value: String?) {
351351
outputStream <<< String(repeating: " ", count: codingPath.count)
352352
outputStream <<< displayName(for: key) <<< ":"
353-
if let value = value { outputStream <<< " " <<< value }
353+
if let value { outputStream <<< " " <<< value }
354354
outputStream <<< "\n"
355355
}
356356
mutating func encodeNil(forKey key: Key) throws { emit(key, "nil") }

Sources/CoreCommands/SwiftTool.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ extension SwiftCommand {
114114
// wait for all observability items to process
115115
swiftTool.waitForObservabilityEvents(timeout: .now() + 5)
116116

117-
if let error = toolError {
118-
throw error
117+
if let toolError {
118+
throw toolError
119119
}
120120
}
121121
}
@@ -150,8 +150,8 @@ extension AsyncSwiftCommand {
150150
// wait for all observability items to process
151151
swiftTool.waitForObservabilityEvents(timeout: .now() + 5)
152152

153-
if let error = toolError {
154-
throw error
153+
if let toolError {
154+
throw toolError
155155
}
156156
}
157157
}
@@ -690,7 +690,7 @@ public final class SwiftTool {
690690
customLogLevel: Basics.Diagnostic.Severity? = .none,
691691
customObservabilityScope: ObservabilityScope? = .none
692692
) throws -> BuildSystem {
693-
guard let buildSystemProvider = buildSystemProvider else {
693+
guard let buildSystemProvider else {
694694
fatalError("build system provider not initialized")
695695
}
696696

Sources/CoreCommands/SwiftToolObservabilityHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private struct InteractiveWriter {
181181

182182
/// Write the string to the contained terminal or stream.
183183
func write(_ string: String, inColor color: TerminalController.Color = .noColor, bold: Bool = false) {
184-
if let term = self.term {
184+
if let term {
185185
term.write(string, inColor: color, bold: bold)
186186
} else {
187187
string.write(to: stream)
@@ -190,7 +190,7 @@ private struct InteractiveWriter {
190190
}
191191

192192
func format(_ string: String, inColor color: TerminalController.Color = .noColor, bold: Bool = false) -> String {
193-
if let term = self.term {
193+
if let term {
194194
return term.wrap(string, inColor: color, bold: bold)
195195
} else {
196196
return string
@@ -202,7 +202,7 @@ private struct InteractiveWriter {
202202
// we should remove this as we make use of the new scope and metadata to provide better contextual information
203203
extension ObservabilityMetadata {
204204
fileprivate var diagnosticPrefix: String? {
205-
if let packageIdentity = self.packageIdentity {
205+
if let packageIdentity {
206206
return "'\(packageIdentity)'"
207207
} else {
208208
return .none

Sources/CrossCompilationDestinationsTool/Configuration/SetConfiguration.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ struct SetConfiguration: ConfigurationCommand {
8787

8888
let currentWorkingDirectory = fileSystem.currentWorkingDirectory
8989

90-
if let sdkRootPath = sdkRootPath {
90+
if let sdkRootPath {
9191
configuration.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: currentWorkingDirectory)
9292
updatedProperties.append(CodingKeys.sdkRootPath.stringValue)
9393
}
9494

95-
if let swiftResourcesPath = swiftResourcesPath {
95+
if let swiftResourcesPath {
9696
configuration.swiftResourcesPath =
9797
try AbsolutePath(validating: swiftResourcesPath, relativeTo: currentWorkingDirectory)
9898
updatedProperties.append(CodingKeys.swiftResourcesPath.stringValue)
9999
}
100100

101-
if let swiftStaticResourcesPath = swiftStaticResourcesPath {
101+
if let swiftStaticResourcesPath {
102102
configuration.swiftResourcesPath =
103103
try AbsolutePath(validating: swiftStaticResourcesPath, relativeTo: currentWorkingDirectory)
104104
updatedProperties.append(CodingKeys.swiftStaticResourcesPath.stringValue)
@@ -147,7 +147,7 @@ struct SetConfiguration: ConfigurationCommand {
147147

148148
extension AbsolutePath {
149149
fileprivate init(validating string: String, relativeTo basePath: AbsolutePath?) throws {
150-
if let basePath = basePath {
150+
if let basePath {
151151
try self.init(validating: string, relativeTo: basePath)
152152
} else {
153153
try self.init(validating: string)

Sources/CrossCompilationDestinationsTool/DestinationCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ extension DestinationCommand {
8484
// wait for all observability items to process
8585
observabilityHandler.wait(timeout: .now() + 5)
8686

87-
if let error = commandError {
88-
throw error
87+
if let commandError {
88+
throw commandError
8989
}
9090
}
9191
}

0 commit comments

Comments
 (0)