From 0d82e21f0fcfe89d9a13dd270439df417ce5f3da Mon Sep 17 00:00:00 2001 From: John Millikin Date: Wed, 8 Nov 2023 09:12:01 +0900 Subject: [PATCH] Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io` Assigned new feature name `core_io_borrowed_buf` to distinguish from the `Read::read_buf` functionality in `std::io`. --- compiler/rustc_span/src/lib.rs | 1 + .../io/readbuf.rs => core/src/io/borrowed_buf.rs} | 15 +-------------- .../readbuf => core/src/io/borrowed_buf}/tests.rs | 0 library/core/src/io/mod.rs | 6 ++++++ library/core/src/lib.rs | 2 ++ library/std/src/io/impls.rs | 13 +++++++++++++ library/std/src/io/mod.rs | 3 +-- library/std/src/lib.rs | 1 + 8 files changed, 25 insertions(+), 16 deletions(-) rename library/{std/src/io/readbuf.rs => core/src/io/borrowed_buf.rs} (97%) rename library/{std/src/io/readbuf => core/src/io/borrowed_buf}/tests.rs (100%) create mode 100644 library/core/src/io/mod.rs diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index fc13bdff36f5..489c8d189265 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -24,6 +24,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] #![feature(cfg_match)] +#![feature(core_io_borrowed_buf)] #![feature(if_let_guard)] #![feature(let_chains)] #![feature(min_specialization)] diff --git a/library/std/src/io/readbuf.rs b/library/core/src/io/borrowed_buf.rs similarity index 97% rename from library/std/src/io/readbuf.rs rename to library/core/src/io/borrowed_buf.rs index 034ddd8df9ae..9cf519007784 100644 --- a/library/std/src/io/readbuf.rs +++ b/library/core/src/io/borrowed_buf.rs @@ -1,10 +1,9 @@ -#![unstable(feature = "read_buf", issue = "78485")] +#![unstable(feature = "core_io_borrowed_buf", issue = "117693")] #[cfg(test)] mod tests; use crate::fmt::{self, Debug, Formatter}; -use crate::io::{Result, Write}; use crate::mem::{self, MaybeUninit}; use crate::{cmp, ptr}; @@ -303,15 +302,3 @@ impl<'a> BorrowedCursor<'a> { self.buf.filled += buf.len(); } } - -impl<'a> Write for BorrowedCursor<'a> { - fn write(&mut self, buf: &[u8]) -> Result { - self.append(buf); - Ok(buf.len()) - } - - #[inline] - fn flush(&mut self) -> Result<()> { - Ok(()) - } -} diff --git a/library/std/src/io/readbuf/tests.rs b/library/core/src/io/borrowed_buf/tests.rs similarity index 100% rename from library/std/src/io/readbuf/tests.rs rename to library/core/src/io/borrowed_buf/tests.rs diff --git a/library/core/src/io/mod.rs b/library/core/src/io/mod.rs new file mode 100644 index 000000000000..2f20180cdc9a --- /dev/null +++ b/library/core/src/io/mod.rs @@ -0,0 +1,6 @@ +//! Traits, helpers, and type definitions for core I/O functionality. + +mod borrowed_buf; + +#[unstable(feature = "core_io_borrowed_buf", issue = "117693")] +pub use self::borrowed_buf::{BorrowedBuf, BorrowedCursor}; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index de643fb333ef..5a6d242a7298 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -369,6 +369,8 @@ pub mod async_iter; pub mod cell; pub mod char; pub mod ffi; +#[unstable(feature = "core_io_borrowed_buf", issue = "117693")] +pub mod io; pub mod iter; pub mod net; pub mod option; diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index f438325560f5..5ecd9652ae4f 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -528,3 +528,16 @@ impl Write for VecDeque { Ok(()) } } + +#[unstable(feature = "read_buf", issue = "78485")] +impl<'a> io::Write for core::io::BorrowedCursor<'a> { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.append(buf); + Ok(buf.len()) + } + + #[inline] + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index aa9a2482d2d9..7d70a0bac24f 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -330,7 +330,7 @@ pub use self::{ }; #[unstable(feature = "read_buf", issue = "78485")] -pub use self::readbuf::{BorrowedBuf, BorrowedCursor}; +pub use core::io::{BorrowedBuf, BorrowedCursor}; pub(crate) use error::const_io_error; mod buffered; @@ -339,7 +339,6 @@ mod cursor; mod error; mod impls; pub mod prelude; -mod readbuf; mod stdio; mod util; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index f57c8d4e7e28..425890122577 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -310,6 +310,7 @@ // tidy-alphabetical-start #![feature(char_internals)] #![feature(core_intrinsics)] +#![feature(core_io_borrowed_buf)] #![feature(duration_constants)] #![feature(error_generic_member_access)] #![feature(error_in_core)]