From 56f6073ea2b5d2c4d3fa9ccf623b2405ee88a9fb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 9 Jan 2023 16:33:34 +0000 Subject: [PATCH 1/2] Allow only implementing `Read::read_buf` --- library/alloc/src/io/read.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/io/read.rs b/library/alloc/src/io/read.rs index c0123c860b453..80b9838df1a72 100644 --- a/library/alloc/src/io/read.rs +++ b/library/alloc/src/io/read.rs @@ -84,6 +84,7 @@ use crate::vec::Vec; #[stable(feature = "rust1", since = "1.0.0")] #[doc(notable_trait)] #[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")] +#[rustc_must_implement_one_of(read, read_buf)] pub trait Read { /// Pull some bytes from this source into the specified buffer, returning /// how many bytes were read. @@ -164,7 +165,10 @@ pub trait Read { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - fn read(&mut self, buf: &mut [u8]) -> Result; + fn read(&mut self, buf: &mut [u8]) -> Result { + let mut buf = BorrowedBuf::from(buf); + self.read_buf(buf.unfilled()).map(|()| buf.len()) + } /// Like `read`, except that it reads into a slice of buffers. /// From 39429fd245eb2cb2aad95ac867cae656709079f4 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 28 Jul 2026 15:02:38 -0700 Subject: [PATCH 2/2] Fix links to `std::io::Read::read` --- library/core/src/io/util.rs | 2 +- tests/rustdoc-html/jump-to-def/non-local-method.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/io/util.rs b/library/core/src/io/util.rs index b022d876eb8f5..07173f13eb08b 100644 --- a/library/core/src/io/util.rs +++ b/library/core/src/io/util.rs @@ -130,7 +130,7 @@ impl Seek for Empty { /// [`Ok(0)`]: Ok /// /// [`write`]: crate::io::Write::write -/// [`read`]: ../../std/io/trait.Read.html#tymethod.read +/// [`read`]: ../../std/io/trait.Read.html#method.read /// /// # Examples /// diff --git a/tests/rustdoc-html/jump-to-def/non-local-method.rs b/tests/rustdoc-html/jump-to-def/non-local-method.rs index e785ab8d204f9..db85d31bf656c 100644 --- a/tests/rustdoc-html/jump-to-def/non-local-method.rs +++ b/tests/rustdoc-html/jump-to-def/non-local-method.rs @@ -16,7 +16,7 @@ use std::cmp::Ordering; use std::marker::PhantomData; pub fn bar2(readable: T) { - //@ has - '//a[@href="{{channel}}/alloc/io/read/trait.Read.html#tymethod.read"]' 'read' + //@ has - '//a[@href="{{channel}}/alloc/io/read/trait.Read.html#method.read"]' 'read' let _ = readable.read(&mut []); }