Skip to content

Commit b40163b

Browse files
committed
Make the Metadata struct Clone
This commit adds #[derive(Clone)] to std::fs::Metadata, making that struct cloneable. Although the exact contents of that struct differ between OSes, they all have it contain only value types, meaning that the data can be re-used without repercussions. It also adds #[derive(Clone)] to every type used by that struct across all OSes, including the various Unix `stat` structs and Windows's `WIN32_FILE_ATTRIBUTE_DATA`.
1 parent ec4362d commit b40163b

File tree

14 files changed

+22
-0
lines changed

14 files changed

+22
-0
lines changed

Diff for: src/libstd/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct File {
6060
/// represents known metadata about a file such as its permissions, size,
6161
/// modification times, etc.
6262
#[stable(feature = "rust1", since = "1.0.0")]
63+
#[derive(Clone)]
6364
pub struct Metadata(fs_imp::FileAttr);
6465

6566
/// Iterator over the entries in a directory.

Diff for: src/libstd/os/android/raw.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mod arch {
3939
pub type time_t = i32;
4040

4141
#[repr(C)]
42+
#[derive(Clone)]
4243
#[stable(feature = "raw_ext", since = "1.1.0")]
4344
pub struct stat {
4445
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -108,6 +109,7 @@ mod arch {
108109
pub type time_t = i64;
109110

110111
#[repr(C)]
112+
#[derive(Clone)]
111113
#[stable(feature = "raw_ext", since = "1.1.0")]
112114
pub struct stat {
113115
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/bitrig/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
2626
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
2727

2828
#[repr(C)]
29+
#[derive(Clone)]
2930
#[stable(feature = "raw_ext", since = "1.1.0")]
3031
pub struct stat {
3132
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/dragonfly/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
2626
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
2727

2828
#[repr(C)]
29+
#[derive(Clone)]
2930
#[stable(feature = "raw_ext", since = "1.1.0")]
3031
pub struct stat {
3132
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/freebsd/raw.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod arch {
3333
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
3434

3535
#[repr(C)]
36+
#[derive(Clone)]
3637
#[stable(feature = "raw_ext", since = "1.1.0")]
3738
pub struct stat {
3839
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -91,6 +92,7 @@ mod arch {
9192
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
9293

9394
#[repr(C)]
95+
#[derive(Clone)]
9496
#[stable(feature = "raw_ext", since = "1.1.0")]
9597
pub struct stat {
9698
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/ios/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use os::unix::raw::{uid_t, gid_t};
2525
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;
2626

2727
#[repr(C)]
28+
#[derive(Clone)]
2829
#[stable(feature = "raw_ext", since = "1.1.0")]
2930
pub struct stat {
3031
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/linux/raw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod arch {
3535
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
3636

3737
#[repr(C)]
38+
#[derive(Clone)]
3839
#[stable(feature = "raw_ext", since = "1.1.0")]
3940
pub struct stat {
4041
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -95,6 +96,7 @@ mod arch {
9596
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
9697

9798
#[repr(C)]
99+
#[derive(Clone)]
98100
#[stable(feature = "raw_ext", since = "1.1.0")]
99101
pub struct stat {
100102
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -154,6 +156,7 @@ mod arch {
154156
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
155157

156158
#[repr(C)]
159+
#[derive(Clone)]
157160
#[stable(feature = "raw_ext", since = "1.1.0")]
158161
pub struct stat {
159162
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -211,6 +214,7 @@ mod arch {
211214
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
212215

213216
#[repr(C)]
217+
#[derive(Clone)]
214218
#[stable(feature = "raw_ext", since = "1.1.0")]
215219
pub struct stat {
216220
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/macos/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use os::unix::raw::{uid_t, gid_t};
2525
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;
2626

2727
#[repr(C)]
28+
#[derive(Clone)]
2829
#[stable(feature = "raw_ext", since = "1.1.0")]
2930
pub struct stat {
3031
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/nacl/raw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mod arch {
3434
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
3535

3636
#[repr(C)]
37+
#[derive(Clone)]
3738
#[stable(feature = "raw_ext", since = "1.1.0")]
3839
pub struct stat {
3940
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -94,6 +95,7 @@ mod arch {
9495
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
9596

9697
#[repr(C)]
98+
#[derive(Clone)]
9799
#[stable(feature = "raw_ext", since = "1.1.0")]
98100
pub struct stat {
99101
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -153,6 +155,7 @@ mod arch {
153155
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
154156

155157
#[repr(C)]
158+
#[derive(Clone)]
156159
#[stable(feature = "raw_ext", since = "1.1.0")]
157160
pub struct stat {
158161
#[stable(feature = "raw_ext", since = "1.1.0")]
@@ -210,6 +213,7 @@ mod arch {
210213
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
211214

212215
#[repr(C)]
216+
#[derive(Clone)]
213217
#[stable(feature = "raw_ext", since = "1.1.0")]
214218
pub struct stat {
215219
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/netbsd/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
2626
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
2727

2828
#[repr(C)]
29+
#[derive(Clone)]
2930
#[stable(feature = "raw_ext", since = "1.1.0")]
3031
pub struct stat {
3132
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/os/openbsd/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
2626
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
2727

2828
#[repr(C)]
29+
#[derive(Clone)]
2930
#[stable(feature = "raw_ext", since = "1.1.0")]
3031
pub struct stat {
3132
#[stable(feature = "raw_ext", since = "1.1.0")]

Diff for: src/libstd/sys/unix/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use vec::Vec;
2727

2828
pub struct File(FileDesc);
2929

30+
#[derive(Clone)]
3031
pub struct FileAttr {
3132
stat: raw::stat,
3233
}

Diff for: src/libstd/sys/windows/c.rs

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pub struct CONSOLE_SCREEN_BUFFER_INFO {
182182
pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO;
183183

184184
#[repr(C)]
185+
#[derive(Clone)]
185186
pub struct WIN32_FILE_ATTRIBUTE_DATA {
186187
pub dwFileAttributes: libc::DWORD,
187188
pub ftCreationTime: libc::FILETIME,

Diff for: src/libstd/sys/windows/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use vec::Vec;
2727

2828
pub struct File { handle: Handle }
2929

30+
#[derive(Clone)]
3031
pub struct FileAttr {
3132
data: c::WIN32_FILE_ATTRIBUTE_DATA,
3233
reparse_tag: libc::DWORD,

0 commit comments

Comments
 (0)