about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-02-04 05:38:04 -0500
committerGitHub <noreply@github.com>2025-02-04 05:38:04 -0500
commit1baf59e5f62e6422badb9ce207f6d5d99326ce0f (patch)
treec3c2f747083eee344fcb9e9c9725c2dd9c900e4f
parent87af17c9784323ed38da9317143f868a5cecd107 (diff)
parent49ea67aa91642708435cb344d0c32fc839e1c4f3 (diff)
downloadrust-1baf59e5f62e6422badb9ce207f6d5d99326ce0f.tar.gz
rust-1baf59e5f62e6422badb9ce207f6d5d99326ce0f.zip
Rollup merge of #136479 - RalfJung:dirent64, r=tgross35
std::fs: further simplify dirent64 handling

Follow-up to https://github.com/rust-lang/rust/pull/134678.

r? `@tgross35`
-rw-r--r--library/std/src/sys/pal/unix/fs.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs
index fdf011c1948..6c41781fe85 100644
--- a/library/std/src/sys/pal/unix/fs.rs
+++ b/library/std/src/sys/pal/unix/fs.rs
@@ -740,29 +740,27 @@ impl Iterator for ReadDir {
                 // to `byte_offset` and thus does not require the full extent of `*entry_ptr`
                 // to be in bounds of the same allocation, only the offset of the field
                 // being referenced.
-                macro_rules! entry_field_ptr {
-                    ($field:ident) => {
-                        &raw const (*entry_ptr).$field
-                    };
-                }
 
                 // d_name is guaranteed to be null-terminated.
-                let name = CStr::from_ptr(entry_field_ptr!(d_name).cast());
+                let name = CStr::from_ptr((&raw const (*entry_ptr).d_name).cast());
                 let name_bytes = name.to_bytes();
                 if name_bytes == b"." || name_bytes == b".." {
                     continue;
                 }
 
+                // When loading from a field, we can skip the `&raw const`; `(*entry_ptr).d_ino` as
+                // a value expression will do the right thing: `byte_offset` to the field and then
+                // only access those bytes.
                 #[cfg(not(target_os = "vita"))]
                 let entry = dirent64_min {
-                    d_ino: *entry_field_ptr!(d_ino) as u64,
+                    d_ino: (*entry_ptr).d_ino as u64,
                     #[cfg(not(any(
                         target_os = "solaris",
                         target_os = "illumos",
                         target_os = "aix",
                         target_os = "nto",
                     )))]
-                    d_type: *entry_field_ptr!(d_type) as u8,
+                    d_type: (*entry_ptr).d_type as u8,
                 };
 
                 #[cfg(target_os = "vita")]