Use unsafe blocks in io module

This commit is contained in:
sourceturner
2026-01-18 21:51:08 +01:00
parent 718dc53b87
commit 0f23c03ba4
4 changed files with 20 additions and 8 deletions
+4 -1
View File
@@ -10,6 +10,9 @@
//! Buffering wrappers for I/O traits
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use core::{cmp, fmt};
use crate::io::{
@@ -172,7 +175,7 @@ impl<R: Read> Read for BufReader<R> {
// we can't skip unconditionally because of the large buffer case in read.
unsafe fn initializer(&self) -> Initializer {
self.inner.initializer()
unsafe { self.inner.initializer() }
}
}
+4 -1
View File
@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use core::cmp;
use crate::io::{self, Error, ErrorKind, Initializer, SeekFrom, prelude::*};
@@ -253,7 +256,7 @@ where
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
unsafe { Initializer::nop() }
}
}
+6 -3
View File
@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use alloc::string::String;
use core::{cmp, fmt, mem};
@@ -21,7 +24,7 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R {
#[inline]
unsafe fn initializer(&self) -> Initializer {
(**self).initializer()
unsafe { (**self).initializer() }
}
#[cfg(feature = "alloc")]
@@ -100,7 +103,7 @@ impl<R: Read + ?Sized> Read for Box<R> {
#[inline]
unsafe fn initializer(&self) -> Initializer {
(**self).initializer()
unsafe { (**self).initializer() }
}
#[cfg(feature = "alloc")]
@@ -200,7 +203,7 @@ impl<'a> Read for &'a [u8] {
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
unsafe { Initializer::nop() }
}
#[inline]
+6 -3
View File
@@ -267,6 +267,9 @@
//! [`Result`]: ../result/enum.Result.html
//! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
pub mod buffered;
pub mod cursor;
pub mod error;
@@ -1393,11 +1396,11 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
}
unsafe fn initializer(&self) -> Initializer {
let initializer = self.first.initializer();
let initializer = unsafe { self.first.initializer() };
if initializer.should_initialize() {
initializer
} else {
self.second.initializer()
unsafe { self.second.initializer() }
}
}
}
@@ -1586,7 +1589,7 @@ impl<T: Read> Read for Take<T> {
}
unsafe fn initializer(&self) -> Initializer {
self.inner.initializer()
unsafe { self.inner.initializer() }
}
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {