diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-01 20:36:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-01 20:36:06 -0700 |
| commit | 441f04b56be65c9228b17adde686b0bda6d38917 (patch) | |
| tree | 4e0026720ac05a73a55b6de21c777255038a983e | |
| parent | 9046f230fde97f5538971ee56c00dea5511822c5 (diff) | |
| parent | b438811029edfb3f39451c91d7e107e0338cf043 (diff) | |
| download | rust-441f04b56be65c9228b17adde686b0bda6d38917.tar.gz rust-441f04b56be65c9228b17adde686b0bda6d38917.zip | |
Rollup merge of #73909 - eltonlaw:unsafe-libstd-fs-rs, r=sfackler
`#[deny(unsafe_op_in_unsafe_fn)]` in libstd/fs.rs The `libstd/fs.rs` part of https://github.com/rust-lang/rust/issues/73904 . Wraps the two calls to an unsafe fn `Initializer::nop()` in an `unsafe` block. Followed instructions in parent issue, ran `./x.py check src/libstd/` after adding the lint and two warnings were given. After adding these changes, those disappear.
| -rw-r--r-- | src/libstd/fs.rs | 7 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 17f890375f8..4d031cb7a52 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; @@ -666,7 +667,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 +713,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")] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 372038df54f..bd585d39c24 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -319,6 +319,7 @@ #![cfg_attr(bootstrap, 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)] |
