Skip to content

Commit e19b286

Browse files
committed
use offset_of in 1.75
1 parent 3ed1f86 commit e19b286

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
- run: |
135135
rustup toolchain install nightly -c clippy
136136
rustup default nightly
137-
- run: cargo clippy --all-targets --all-features -- -Dwarnings
137+
- run: cargo clippy --all-targets --all-features -- -Dwarnings -A clippy::assertions-on-constants
138138

139139

140140
# Use static analyzer Rudra <https://github.com/sslab-gatech/Rudra>.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ description = "library for working with NTFS junctions"
1818

1919
[features]
2020
default = ["unstable_admin"]
21+
# Flag for trying out new rust language features
22+
nightly = []
2123
# # Unstable flag
2224
#
2325
# Enable the SE_BACKUP_NAME and SE_RESTORE_NAME access privileges.

src/internals/c.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#![allow(non_snake_case)]
22

3+
// MSRV(1.75): use `offset_of!` when stabilized.
4+
#[cfg(feature = "nightly")]
5+
mod nightly;
6+
37
use std::alloc::Layout;
4-
use std::mem::size_of;
58
use std::os::raw::{c_ulong, c_ushort};
69
use std::os::windows::io::RawHandle;
710

8-
use windows_sys::core::GUID;
911
pub use windows_sys::Win32::Foundation::{
1012
CloseHandle, GetLastError, SetLastError, ERROR_INSUFFICIENT_BUFFER, FALSE, GENERIC_READ, GENERIC_WRITE, HANDLE,
1113
INVALID_HANDLE_VALUE,
@@ -39,26 +41,18 @@ const _: () = {
3941
};
4042

4143
// NOTE: to use `size_of` operator, below structs should be packed.
42-
// TODO: use `offset_of!` when stabilized.
4344
/// Reparse Data Buffer header size
4445
pub const REPARSE_DATA_BUFFER_HEADER_SIZE: u16 = 8;
4546
/// Reparse GUID Data Buffer header size
4647
pub const REPARSE_GUID_DATA_BUFFER_HEADER_SIZE: u16 = 24;
4748
/// MountPointReparseBuffer header size
4849
pub const MOUNT_POINT_REPARSE_BUFFER_HEADER_SIZE: u16 = 8;
4950

50-
// Safety checks for correct header size due to the lacks of `offset_of!`.
51-
// MSRV(1.57): for const assert!
52-
#[allow(clippy::no_effect)] // noisy clippy lints
51+
#[cfg(feature = "nightly")]
5352
const _: () = {
54-
let rdb_header_size = size_of::<c_ulong>() + size_of::<c_ushort>() * 2;
55-
[(); 1][!(rdb_header_size == REPARSE_DATA_BUFFER_HEADER_SIZE as _) as usize];
56-
57-
let mprb_header_size = size_of::<c_ushort>() * 4;
58-
[(); 1][!(mprb_header_size == MOUNT_POINT_REPARSE_BUFFER_HEADER_SIZE as _) as usize];
59-
60-
let rgdb_header_size = size_of::<c_ulong>() + size_of::<c_ushort>() * 2 + size_of::<GUID>();
61-
[(); 1][!(rgdb_header_size == REPARSE_GUID_DATA_BUFFER_HEADER_SIZE as _) as usize];
53+
assert!(REPARSE_DATA_BUFFER_HEADER_SIZE == nightly::REPARSE_DATA_BUFFER_HEADER_SIZE);
54+
assert!(REPARSE_GUID_DATA_BUFFER_HEADER_SIZE == nightly::REPARSE_GUID_DATA_BUFFER_HEADER_SIZE);
55+
assert!(MOUNT_POINT_REPARSE_BUFFER_HEADER_SIZE == nightly::MOUNT_POINT_REPARSE_BUFFER_HEADER_SIZE);
6256
};
6357

6458
type VarLenArr<T> = [T; 1];

src/internals/c/nightly.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![allow(unused)]
2+
3+
use std::mem::offset_of;
4+
5+
/// Reparse Data Buffer header size
6+
pub const REPARSE_DATA_BUFFER_HEADER_SIZE: u16 = offset_of!(super::REPARSE_DATA_BUFFER, ReparseBuffer) as u16;
7+
/// Reparse GUID Data Buffer header size
8+
pub const REPARSE_GUID_DATA_BUFFER_HEADER_SIZE: u16 =
9+
offset_of!(super::REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer) as u16;
10+
/// MountPointReparseBuffer header size
11+
pub const MOUNT_POINT_REPARSE_BUFFER_HEADER_SIZE: u16 = offset_of!(super::MountPointReparseBuffer, PathBuffer) as u16;

0 commit comments

Comments
 (0)