Skip to content

Commit f834898

Browse files
authored
refactor: resolve all new nightly clippy failures (#32)
1 parent 832fa45 commit f834898

File tree

9 files changed

+176
-54
lines changed

9 files changed

+176
-54
lines changed

.github/actions/winget-install/action.yml

+16-11
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,42 @@ inputs:
77
runs:
88
using: "composite"
99
steps:
10-
- name: Get URIs for Latest Winget assets
10+
- name: Get URIs for Winget v1.8.1911 assets
1111
shell: pwsh
1212
run: |
1313
$AuthenticatedHeaders = @{ "Authorization" = "Bearer ${{ inputs.GITHUB_TOKEN }}" }
1414
15-
$LatestReleaseInfo = Invoke-RestMethod -Headers $AuthenticatedHeaders 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
16-
$LatestWingetDownloadUri = $LatestReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('.msixbundle') }
17-
$LatestWingetLicenseDownloadUri = $LatestReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('License1.xml') }
15+
$ReleaseInfo = Invoke-RestMethod -Headers $AuthenticatedHeaders 'https://api.github.com/repos/microsoft/winget-cli/releases/164835566'
16+
$WingetDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('.msixbundle') }
17+
$WingetLicenseDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('License1.xml') }
1818
1919
# Print to logs
20-
Write-Host "LatestWingetDownloadUri=$LatestWingetDownloadUri"
21-
Write-Host "LatestWingetLicenseDownloadUri=$LatestWingetLicenseDownloadUri"
20+
Write-Host "WingetDownloadUri=$WingetDownloadUri"
21+
Write-Host "WingetLicenseDownloadUri=$WingetLicenseDownloadUri"
2222
2323
# Save output for next step
24-
Write-Output "LatestWingetDownloadUri=$LatestWingetDownloadUri" >> $env:GITHUB_ENV
25-
Write-Output "LatestWingetLicenseDownloadUri=$LatestWingetLicenseDownloadUri" >> $env:GITHUB_ENV
24+
Write-Output "WingetDownloadUri=$WingetDownloadUri" >> $env:GITHUB_ENV
25+
Write-Output "WingetLicenseDownloadUri=$WingetLicenseDownloadUri" >> $env:GITHUB_ENV
2626
2727
- name: Download Winget Assets and Dependencies
2828
shell: pwsh
2929
run: |
3030
New-Item -Type Directory $env:RUNNER_TEMP/winget-install
3131
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx
3232
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx # Needed per https://github.com/microsoft/winget-cli/blob/21de1607ed5c90174e6bb931406975c18681a5dd/README.md?plain=1#L35C19-L35C19
33-
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/winget.msixbundle
34-
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetLicenseDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/license.xml
33+
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/winget.msixbundle
34+
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetLicenseDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/license.xml
3535
36-
- name: Start Winget Installation
36+
- name: Start Winget Installation for all Users
3737
shell: pwsh
3838
run: |
3939
Add-AppxProvisionedPackage -Online -PackagePath $env:RUNNER_TEMP/winget-install/winget.msixbundle -LicensePath $env:RUNNER_TEMP/winget-install/license.xml -DependencyPackagePath $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx, $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx
4040
41+
- name: Install Winget for Current User (for better install diagnostics)
42+
shell: powershell
43+
run: |
44+
Add-AppxPackage $env:RUNNER_TEMP/winget-install/winget.msixbundle
45+
4146
- name: Wait for Completion of Winget Installation
4247
shell: pwsh
4348
run: |

.github/workflows/lint.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ jobs:
7171
targets: ${{ matrix.target_triple }}
7272

7373
- name: Run Cargo Clippy
74-
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets
74+
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets -- -D warnings
7575

7676
- name: Run Cargo Clippy (--features nightly)
7777
if: matrix.rust_toolchain == 'nightly'
78-
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets --features nightly
78+
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets --features nightly -- -D warnings
7979

8080
udeps:
8181
name: Detect Unused Cargo Dependencies

general/echo/kmdf/driver/DriverSync/src/device.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use wdk_sys::{
77
APC_LEVEL,
88
NTSTATUS,
99
STATUS_SUCCESS,
10-
ULONG,
1110
WDFDEVICE,
1211
WDFDEVICE_INIT,
1312
WDFOBJECT,
@@ -28,6 +27,8 @@ use crate::{
2827
KeGetCurrentIrql,
2928
GUID_DEVINTERFACE_ECHO,
3029
WDF_DEVICE_CONTEXT_TYPE_INFO,
30+
WDF_OBJECT_ATTRIBUTES_SIZE,
31+
WDF_PNPPOWER_EVENT_CALLBACKS_SIZE,
3132
WDF_REQUEST_CONTEXT_TYPE_INFO,
3233
};
3334

@@ -49,7 +50,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
4950
// Register pnp/power callbacks so that we can start and stop the timer as the
5051
// device gets started and stopped.
5152
let mut pnp_power_callbacks = WDF_PNPPOWER_EVENT_CALLBACKS {
52-
Size: core::mem::size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() as ULONG,
53+
Size: WDF_PNPPOWER_EVENT_CALLBACKS_SIZE,
5354
EvtDeviceSelfManagedIoInit: Some(echo_evt_device_self_managed_io_start),
5455
EvtDeviceSelfManagedIoSuspend: Some(echo_evt_device_self_managed_io_suspend),
5556
// Function used for both Init and Restart Callbacks
@@ -68,7 +69,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
6869
};
6970

7071
let mut attributes = WDF_OBJECT_ATTRIBUTES {
71-
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
72+
Size: WDF_OBJECT_ATTRIBUTES_SIZE,
7273
ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent,
7374
SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent,
7475
ContextTypeInfo: wdf_get_context_type_info!(RequestContext),
@@ -84,7 +85,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
8485
};
8586

8687
let mut attributes = WDF_OBJECT_ATTRIBUTES {
87-
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
88+
Size: WDF_OBJECT_ATTRIBUTES_SIZE,
8889
ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent,
8990
SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent,
9091
ContextTypeInfo: wdf_get_context_type_info!(DeviceContext),
@@ -95,7 +96,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
9596
let mut nt_status = unsafe {
9697
call_unsafe_wdf_function_binding!(
9798
WdfDeviceCreate,
98-
(core::ptr::addr_of_mut!(device_init)) as *mut *mut WDFDEVICE_INIT,
99+
(core::ptr::addr_of_mut!(device_init)).cast(),
99100
&mut attributes,
100101
&mut device,
101102
)

general/echo/kmdf/driver/DriverSync/src/driver.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use wdk_sys::{
1212
PDRIVER_OBJECT,
1313
PWDFDEVICE_INIT,
1414
STATUS_SUCCESS,
15-
ULONG,
1615
UNICODE_STRING,
1716
WDFDRIVER,
1817
WDFOBJECT,
@@ -23,7 +22,7 @@ use wdk_sys::{
2322
WDF_NO_OBJECT_ATTRIBUTES,
2423
};
2524

26-
use crate::device;
25+
use crate::{device, WDF_DRIVER_CONFIG_SIZE, WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE};
2726

2827
extern crate alloc;
2928

@@ -55,7 +54,7 @@ extern "system" fn driver_entry(
5554
registry_path: PCUNICODE_STRING,
5655
) -> NTSTATUS {
5756
let mut driver_config = WDF_DRIVER_CONFIG {
58-
Size: core::mem::size_of::<WDF_DRIVER_CONFIG>() as ULONG,
57+
Size: WDF_DRIVER_CONFIG_SIZE,
5958
EvtDriverDeviceAdd: Some(echo_evt_device_add),
6059
..WDF_DRIVER_CONFIG::default()
6160
};
@@ -167,12 +166,11 @@ fn echo_print_driver_version() -> NTSTATUS {
167166
unsafe {
168167
call_unsafe_wdf_function_binding!(WdfObjectDelete, string as WDFOBJECT);
169168
};
170-
// string = core::ptr::null_mut();
171169

172170
// 2) Find out to which version of framework this driver is bound to.
173171
//
174172
let mut ver = WDF_DRIVER_VERSION_AVAILABLE_PARAMS {
175-
Size: core::mem::size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() as ULONG,
173+
Size: WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE,
176174
MajorVersion: 1,
177175
MinorVersion: 0,
178176
};

general/echo/kmdf/driver/DriverSync/src/lib.rs

+117
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ use wdk_sys::{
5454
ULONG,
5555
WDFOBJECT,
5656
WDFREQUEST,
57+
WDF_DRIVER_CONFIG,
58+
WDF_DRIVER_VERSION_AVAILABLE_PARAMS,
59+
WDF_IO_QUEUE_CONFIG,
60+
WDF_OBJECT_ATTRIBUTES,
5761
WDF_OBJECT_CONTEXT_TYPE_INFO,
62+
WDF_PNPPOWER_EVENT_CALLBACKS,
63+
WDF_TIMER_CONFIG,
5864
};
5965
mod wdf_object_context;
6066
use core::sync::atomic::AtomicI32;
@@ -100,3 +106,114 @@ pub struct RequestContext {
100106
cancel_completion_ownership_count: AtomicI32,
101107
}
102108
wdf_declare_context_type_with_name!(RequestContext, request_get_context);
109+
110+
// None of the below SIZE constants should be needed after an equivalent `WDF_STRUCTURE_SIZE` macro is added to `wdk-sys`: https://github.com/microsoft/windows-drivers-rs/issues/242
111+
112+
#[allow(
113+
clippy::cast_possible_truncation,
114+
reason = "size_of::<WDF_DRIVER_CONFIG>() is known to fit in ULONG due to below const assert"
115+
)]
116+
const WDF_DRIVER_CONFIG_SIZE: ULONG = {
117+
const S: usize = core::mem::size_of::<WDF_DRIVER_CONFIG>();
118+
const {
119+
assert!(
120+
S <= ULONG::MAX as usize,
121+
"size_of::<WDF_DRIVER_CONFIG>() should fit in ULONG"
122+
);
123+
};
124+
S as ULONG
125+
};
126+
127+
#[allow(
128+
clippy::cast_possible_truncation,
129+
reason = "size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() is known to fit in ULONG due to \
130+
below const assert"
131+
)]
132+
const WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE: ULONG = {
133+
const S: usize = core::mem::size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>();
134+
const {
135+
assert!(
136+
S <= ULONG::MAX as usize,
137+
"size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() should fit in ULONG"
138+
);
139+
};
140+
S as ULONG
141+
};
142+
143+
#[allow(
144+
clippy::cast_possible_truncation,
145+
reason = "size_of::<WDF_IO_QUEUE_CONFIG>() is known to fit in ULONG due to below const assert"
146+
)]
147+
const WDF_IO_QUEUE_CONFIG_SIZE: ULONG = {
148+
const S: usize = core::mem::size_of::<WDF_IO_QUEUE_CONFIG>();
149+
const {
150+
assert!(
151+
S <= ULONG::MAX as usize,
152+
"size_of::<WDF_IO_QUEUE_CONFIG>() should fit in ULONG"
153+
);
154+
};
155+
S as ULONG
156+
};
157+
158+
#[allow(
159+
clippy::cast_possible_truncation,
160+
reason = "size_of::<WDF_OBJECT_ATTRIBUTES>() is known to fit in ULONG due to below const \
161+
assert"
162+
)]
163+
const WDF_OBJECT_ATTRIBUTES_SIZE: ULONG = {
164+
const S: usize = core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>();
165+
const {
166+
assert!(
167+
S <= ULONG::MAX as usize,
168+
"size_of::<WDF_OBJECT_ATTRIBUTES>() should fit in ULONG"
169+
);
170+
};
171+
S as ULONG
172+
};
173+
174+
#[allow(
175+
clippy::cast_possible_truncation,
176+
reason = "size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>() is known to fit in ULONG due to below \
177+
const assert"
178+
)]
179+
const WDF_OBJECT_CONTEXT_TYPE_INFO_SIZE: ULONG = {
180+
const S: usize = core::mem::size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>();
181+
const {
182+
assert!(
183+
S <= ULONG::MAX as usize,
184+
"size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>() should fit in ULONG"
185+
);
186+
};
187+
S as ULONG
188+
};
189+
190+
#[allow(
191+
clippy::cast_possible_truncation,
192+
reason = "size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() is known to fit in ULONG due to below \
193+
const assert"
194+
)]
195+
const WDF_PNPPOWER_EVENT_CALLBACKS_SIZE: ULONG = {
196+
const S: usize = core::mem::size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>();
197+
const {
198+
assert!(
199+
S <= ULONG::MAX as usize,
200+
"size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() should fit in ULONG"
201+
);
202+
};
203+
S as ULONG
204+
};
205+
206+
#[allow(
207+
clippy::cast_possible_truncation,
208+
reason = "size_of::<WDF_TIMER_CONFIG>() is known to fit in ULONG due to below const assert"
209+
)]
210+
const WDF_TIMER_CONFIG_SIZE: ULONG = {
211+
const S: usize = core::mem::size_of::<WDF_TIMER_CONFIG>();
212+
const {
213+
assert!(
214+
S <= ULONG::MAX as usize,
215+
"size_of::<WDF_TIMER_CONFIG>() should fit in ULONG"
216+
);
217+
};
218+
S as ULONG
219+
};

0 commit comments

Comments
 (0)