From 7616cd9ee9c2eb0cec7b76d608af7c8fad7704d4 Mon Sep 17 00:00:00 2001 From: Elton Law Date: Tue, 30 Jun 2020 22:51:28 -0400 Subject: [PATCH 1/2] `#[deny(unsafe_op_in_unsafe_fn)]` in libstd/fs.rs --- src/libstd/fs.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 17f890375f843..bdcbd46c0d813 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -666,7 +666,8 @@ impl Read for File { #[inline] unsafe fn initializer(&self) -> Initializer { - Initializer::nop() + // SAFETY: Read is guaranteed to work on uninitialized memory + unsafe { Initializer::nop() } } } #[stable(feature = "rust1", since = "1.0.0")] @@ -711,7 +712,8 @@ impl Read for &File { #[inline] unsafe fn initializer(&self) -> Initializer { - Initializer::nop() + // SAFETY: Read is guaranteed to work on uninitialized memory + unsafe { Initializer::nop() } } } #[stable(feature = "rust1", since = "1.0.0")] From b438811029edfb3f39451c91d7e107e0338cf043 Mon Sep 17 00:00:00 2001 From: Elton Law Date: Tue, 30 Jun 2020 23:09:06 -0400 Subject: [PATCH 2/2] enable unsafe_op_in_unsafe_fn lint --- src/libstd/fs.rs | 1 + src/libstd/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index bdcbd46c0d813..4d031cb7a52e4 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -8,6 +8,7 @@ //! extension traits of `std::os::$platform`. #![stable(feature = "rust1", since = "1.0.0")] +#![deny(unsafe_op_in_unsafe_fn)] use crate::ffi::OsString; use crate::fmt; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ef699ede2a140..1833d35bdde31 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -319,6 +319,7 @@ #![feature(track_caller)] #![feature(try_reserve)] #![feature(unboxed_closures)] +#![feature(unsafe_block_in_unsafe_fn)] #![feature(untagged_unions)] #![feature(unwind_attributes)] #![feature(vec_into_raw_parts)]