Skip to content

Commit 441f04b

Browse files
authored
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 #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.
2 parents 9046f23 + b438811 commit 441f04b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/libstd/fs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! extension traits of `std::os::$platform`.
99
1010
#![stable(feature = "rust1", since = "1.0.0")]
11+
#![deny(unsafe_op_in_unsafe_fn)]
1112

1213
use crate::ffi::OsString;
1314
use crate::fmt;
@@ -666,7 +667,8 @@ impl Read for File {
666667

667668
#[inline]
668669
unsafe fn initializer(&self) -> Initializer {
669-
Initializer::nop()
670+
// SAFETY: Read is guaranteed to work on uninitialized memory
671+
unsafe { Initializer::nop() }
670672
}
671673
}
672674
#[stable(feature = "rust1", since = "1.0.0")]
@@ -711,7 +713,8 @@ impl Read for &File {
711713

712714
#[inline]
713715
unsafe fn initializer(&self) -> Initializer {
714-
Initializer::nop()
716+
// SAFETY: Read is guaranteed to work on uninitialized memory
717+
unsafe { Initializer::nop() }
715718
}
716719
}
717720
#[stable(feature = "rust1", since = "1.0.0")]

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@
319319
#![cfg_attr(bootstrap, feature(track_caller))]
320320
#![feature(try_reserve)]
321321
#![feature(unboxed_closures)]
322+
#![feature(unsafe_block_in_unsafe_fn)]
322323
#![feature(untagged_unions)]
323324
#![feature(unwind_attributes)]
324325
#![feature(vec_into_raw_parts)]

0 commit comments

Comments
 (0)