Skip to content

Commit 2ab3ee5

Browse files
committed
Remove unnecessary type casting
The compiler now imports these as their canonical type, allowing us to directly use without the explicit type cast.
1 parent 14e464c commit 2ab3ee5

14 files changed

Lines changed: 26 additions & 27 deletions

File tree

Sources/Overlays/_Testing_Foundation/Attachments/Attachment+URL.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ private let _archiverPath: String? = {
131131
return _archiverName.withCString(encodedAs: UTF16.self) { archiverName -> String? in
132132
var result: UnsafeMutablePointer<CWideChar>?
133133

134-
let flags = ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue)
135-
guard S_OK == PathAllocCombine(buffer.baseAddress!, archiverName, flags, &result) else {
134+
guard S_OK == PathAllocCombine(buffer.baseAddress!, archiverName, DWORD(PATHCCH_ALLOW_LONG_PATHS.rawValue), &result) else {
136135
return nil
137136
}
138137
defer {

Sources/Overlays/_Testing_WinSDK/Attachments/HBITMAP+AttachableAsIWICBitmapSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension HBITMAP__: _AttachableByAddressAsIWICBitmapSource {
2828
// The only reasonable failure mode for `CopyImage()` is allocation failure,
2929
// and Swift treats allocation failures as fatal. Hence, we do not check for
3030
// `nil` on return.
31-
CopyImage(imageAddress, UINT(IMAGE_BITMAP), 0, 0, 0).assumingMemoryBound(to: Self.self)
31+
CopyImage(imageAddress, IMAGE_BITMAP, 0, 0, 0).assumingMemoryBound(to: Self.self)
3232
}
3333

3434
public static func _deinitializeAttachableValue(at imageAddress: UnsafeMutablePointer<Self>) {

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ extension ExitTest {
242242
// On Windows, similarly disable Windows Error Reporting and the Windows
243243
// Error Reporting UI. Note we expect to be the first component to call
244244
// these functions, so we don't attempt to preserve any previously-set bits.
245-
_ = SetErrorMode(UINT(SEM_NOGPFAULTERRORBOX))
246-
_ = WerSetFlags(DWORD(WER_FAULT_REPORTING_NO_UI))
245+
_ = SetErrorMode(SEM_NOGPFAULTERRORBOX)
246+
_ = WerSetFlags(WER_FAULT_REPORTING_NO_UI)
247247
#else
248248
#warning("Platform-specific implementation missing: unable to disable crash reporting")
249249
#endif

Sources/Testing/ExitTests/SpawnProcess.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func spawnExecutable(
258258
}
259259

260260
// Ensure the file handle can be inherited by the child process.
261-
guard SetHandleInformation(windowsHANDLE, DWORD(HANDLE_FLAG_INHERIT), DWORD(HANDLE_FLAG_INHERIT)) else {
261+
guard SetHandleInformation(windowsHANDLE, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) else {
262262
throw Win32Error(rawValue: GetLastError())
263263
}
264264

@@ -326,13 +326,13 @@ func spawnExecutable(
326326
// SEE: https://devblogs.microsoft.com/oldnewthing/20101109-00/?p=12323
327327
let workingDirectoryPath = rootDirectoryPath
328328

329-
var flags = DWORD(CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT)
329+
var flags = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT
330330

331331
// Start the process suspended so we can attach a debugger if needed. We
332332
// always start the child process in a suspended state even if the
333333
// "SWT_START_CHILD_PROCESSES_SUSPENDED" environment variable isn't set so that
334334
// the debugger has a chance to attach to the child.
335-
flags |= DWORD(CREATE_SUSPENDED)
335+
flags |= CREATE_SUSPENDED
336336

337337
return try environ.withCString(encodedAs: UTF16.self) { environ in
338338
try workingDirectoryPath.withCString(encodedAs: UTF16.self) { workingDirectoryPath in

Sources/Testing/ExitTests/WaitFor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func wait(for processHandle: consuming HANDLE) async throws -> ExitStatus {
296296

297297
// We only want the callback to fire once (and not be rescheduled.) Waiting
298298
// may take an arbitrarily long time, so let the thread pool know that too.
299-
let flags = ULONG(WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION)
299+
let flags = WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION
300300
guard RegisterWaitForSingleObject(&waitHandle, processHandle, callback, context, INFINITE, flags) else {
301301
continuation.resume(throwing: Win32Error(rawValue: GetLastError()))
302302
return

Sources/Testing/SourceAttribution/Backtrace+Symbolication.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension Backtrace {
8686
withUnsafeTemporaryAllocation(of: SYMBOL_INFO_PACKAGEW.self, capacity: 1) { symbolInfo in
8787
let symbolInfo = symbolInfo.baseAddress!
8888
symbolInfo.pointee.si.SizeOfStruct = ULONG(MemoryLayout<SYMBOL_INFOW>.stride)
89-
symbolInfo.pointee.si.MaxNameLen = ULONG(MAX_SYM_NAME)
89+
symbolInfo.pointee.si.MaxNameLen = MAX_SYM_NAME
9090
var displacement = DWORD64(0)
9191
if SymFromAddrW(hProcess, DWORD64(clamping: address), &displacement, symbolInfo.pointer(to: \.si)!) {
9292
let symbolName = String.decodeCString(symbolInfo.pointer(to: \.si.Name)!, as: UTF16.self)?.result

Sources/Testing/Support/Additions/CommandLineAdditions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ extension CommandLine {
108108
#endif
109109
while result == nil {
110110
try withUnsafeTemporaryAllocation(of: CWideChar.self, capacity: bufferCount) { buffer in
111-
SetLastError(DWORD(ERROR_SUCCESS))
111+
SetLastError(ERROR_SUCCESS)
112112
_ = GetModuleFileNameW(nil, buffer.baseAddress!, DWORD(buffer.count))
113113
switch GetLastError() {
114-
case DWORD(ERROR_SUCCESS):
114+
case ERROR_SUCCESS:
115115
result = String.decodeCString(buffer.baseAddress!, as: UTF16.self)?.result
116116
if result == nil {
117-
throw Win32Error(rawValue: DWORD(ERROR_ILLEGAL_CHARACTER))
117+
throw Win32Error(rawValue: ERROR_ILLEGAL_CHARACTER)
118118
}
119-
case DWORD(ERROR_INSUFFICIENT_BUFFER):
119+
case ERROR_INSUFFICIENT_BUFFER:
120120
bufferCount += Int(MAX_PATH)
121121
case let errorCode:
122122
throw Win32Error(rawValue: errorCode)

Sources/Testing/Support/CError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension Win32Error: CustomStringConvertible {
9797
// we need to temporarily mis-cast the pointer before we can pass it in.
9898
let count = buffer.withMemoryRebound(to: CWideChar.self) { buffer in
9999
FormatMessageW(
100-
DWORD(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK),
100+
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
101101
nil,
102102
rawValue,
103103
DWORD(swt_MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)),

Sources/Testing/Support/Environment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ package enum Environment {
199199
name.withCString(encodedAs: UTF16.self) { name in
200200
func getVariable(maxCount: Int) -> String? {
201201
withUnsafeTemporaryAllocation(of: CWideChar.self, capacity: maxCount) { buffer in
202-
SetLastError(DWORD(ERROR_SUCCESS))
202+
SetLastError(ERROR_SUCCESS)
203203
let count = GetEnvironmentVariableW(name, buffer.baseAddress!, DWORD(buffer.count))
204204
if count == 0 {
205205
switch GetLastError() {
206-
case DWORD(ERROR_SUCCESS):
206+
case ERROR_SUCCESS:
207207
// Empty String
208208
return ""
209-
case DWORD(ERROR_ENVVAR_NOT_FOUND):
209+
case ERROR_ENVVAR_NOT_FOUND:
210210
// The environment variable wasn't set.
211211
return nil
212212
case let errorCode:

Sources/_TestDiscovery/Additions/WinSDKAdditions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension HMODULE {
4242
}
4343
} else {
4444
// Create a toolhelp snapshot that lists modules.
45-
guard let snapshot = CreateToolhelp32Snapshot(DWORD(TH32CS_SNAPMODULE), 0) else {
45+
guard let snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0) else {
4646
return nil
4747
}
4848
state.snapshot = snapshot

0 commit comments

Comments
 (0)