Skip to content

Commit

Permalink
Auto merge of #29021 - ogham:master, r=alexcrichton
Browse files Browse the repository at this point in the history
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`.

This stems from my comment here: rust-lang/rfcs#939 (comment)
  • Loading branch information
bors committed Oct 15, 2015
2 parents 9c9615e + b40163b commit 1ad1b7d
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct File {
/// represents known metadata about a file such as its permissions, size,
/// modification times, etc.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone)]
pub struct Metadata(fs_imp::FileAttr);

/// Iterator over the entries in a directory.
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/os/android/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod arch {
pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -108,6 +109,7 @@ mod arch {
pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/bitrig/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/dragonfly/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/os/freebsd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -91,6 +92,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/ios/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -95,6 +96,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -154,6 +156,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -211,6 +214,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/macos/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/os/nacl/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -94,6 +95,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -153,6 +155,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down Expand Up @@ -210,6 +213,7 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/netbsd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/openbsd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use vec::Vec;

pub struct File(FileDesc);

#[derive(Clone)]
pub struct FileAttr {
stat: raw::stat,
}
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub struct CONSOLE_SCREEN_BUFFER_INFO {
pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO;

#[repr(C)]
#[derive(Clone)]
pub struct WIN32_FILE_ATTRIBUTE_DATA {
pub dwFileAttributes: libc::DWORD,
pub ftCreationTime: libc::FILETIME,
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use vec::Vec;

pub struct File { handle: Handle }

#[derive(Clone)]
pub struct FileAttr {
data: c::WIN32_FILE_ATTRIBUTE_DATA,
reparse_tag: libc::DWORD,
Expand Down

0 comments on commit 1ad1b7d

Please sign in to comment.