diff --git a/library/std/src/sys/fs/unsupported.rs b/library/std/src/sys/fs/unsupported.rs index 512af27401dfe..b0ad9a9c96dc8 100644 --- a/library/std/src/sys/fs/unsupported.rs +++ b/library/std/src/sys/fs/unsupported.rs @@ -29,6 +29,25 @@ pub struct FileType(!); #[derive(Debug)] pub struct DirBuilder {} +// Dummy Drops so that `needs_drop::()` etc. is true independent of platform, +// avoiding a portability hazard. +// The types not listed here are pure data and don’t implement Drop even when real. +impl Drop for File { + fn drop(&mut self) { + self.0 + } +} +impl Drop for ReadDir { + fn drop(&mut self) { + self.0 + } +} +impl Drop for DirEntry { + fn drop(&mut self) { + self.0 + } +} + impl FileAttr { pub fn size(&self) -> u64 { self.0 diff --git a/library/std/src/sys/fs/vexos.rs b/library/std/src/sys/fs/vexos.rs index 1357787c44c77..c2417627c0b9d 100644 --- a/library/std/src/sys/fs/vexos.rs +++ b/library/std/src/sys/fs/vexos.rs @@ -477,6 +477,13 @@ impl Drop for File { } } +impl Drop for ReadDir { + fn drop(&mut self) { + // Dummy Drop so that `needs_drop::()` is true independent of platform. + self.0 + } +} + pub fn readdir(_p: &Path) -> io::Result { // While there *is* a userspace function for reading file directories, // the necessary implementation cannot currently be done cleanly, as