Skip to content

Commit

Permalink
notable trait for impls
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Feb 22, 2023
1 parent bd4a96a commit 9055128
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,7 @@ impl<'a> Formatter<'a> {
}

#[stable(since = "1.2.0", feature = "formatter_write")]
#[doc(notable_trait)]
impl Write for Formatter<'_> {
fn write_str(&mut self, s: &str) -> Result {
self.buf.write_str(s)
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ fn buffer_capacity_required(mut file: &File) -> usize {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for File {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
Expand Down Expand Up @@ -772,6 +773,7 @@ impl Read for File {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for File {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.write(buf)
Expand All @@ -797,6 +799,7 @@ impl Seek for File {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for &File {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
Expand Down Expand Up @@ -828,6 +831,7 @@ impl Read for &File {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for &File {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.write(buf)
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for Cursor<&mut [u8]> {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand All @@ -543,6 +544,7 @@ impl Write for Cursor<&mut [u8]> {
}

#[stable(feature = "cursor_mut_vec", since = "1.25.0")]
#[doc(notable_trait)]
impl<A> Write for Cursor<&mut Vec<u8, A>>
where
A: Allocator,
Expand All @@ -567,6 +569,7 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl<A> Write for Cursor<Vec<u8, A>>
where
A: Allocator,
Expand All @@ -591,6 +594,7 @@ where
}

#[stable(feature = "cursor_box_slice", since = "1.5.0")]
#[doc(notable_trait)]
impl<A> Write for Cursor<Box<[u8], A>>
where
A: Allocator,
Expand All @@ -617,6 +621,7 @@ where
}

#[stable(feature = "cursor_array", since = "1.61.0")]
#[doc(notable_trait)]
impl<const N: usize> Write for Cursor<[u8; N]> {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ where
/// [`std::io`]: self
/// [`File`]: crate::fs::File
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
#[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")]
pub trait Read {
/// Pull some bytes from this source into the specified buffer, returning
Expand Down Expand Up @@ -1380,7 +1379,6 @@ impl<'a> Deref for IoSlice<'a> {
///
/// [`write_all`]: Write::write_all
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
#[cfg_attr(not(test), rustc_diagnostic_item = "IoWrite")]
pub trait Write {
/// Write a buffer into this writer, returning how many bytes were written.
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ impl fmt::Debug for Stdin {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.lock().read(buf)
Expand Down Expand Up @@ -445,6 +446,7 @@ impl StdinLock<'_> {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for StdinLock<'_> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
Expand Down Expand Up @@ -665,6 +667,7 @@ impl fmt::Debug for Stdout {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for Stdout {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&*self).write(buf)
Expand All @@ -691,6 +694,7 @@ impl Write for Stdout {
}

#[stable(feature = "write_mt", since = "1.48.0")]
#[doc(notable_trait)]
impl Write for &Stdout {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.lock().write(buf)
Expand All @@ -717,6 +721,7 @@ impl Write for &Stdout {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for StdoutLock<'_> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.borrow_mut().write(buf)
Expand Down Expand Up @@ -884,6 +889,7 @@ impl fmt::Debug for Stderr {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for Stderr {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&*self).write(buf)
Expand All @@ -910,6 +916,7 @@ impl Write for Stderr {
}

#[stable(feature = "write_mt", since = "1.48.0")]
#[doc(notable_trait)]
impl Write for &Stderr {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.lock().write(buf)
Expand All @@ -936,6 +943,7 @@ impl Write for &Stderr {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for StderrLock<'_> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.borrow_mut().write(buf)
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub const fn empty() -> Empty {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for Empty {
#[inline]
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
Expand Down Expand Up @@ -121,6 +122,7 @@ pub const fn repeat(byte: u8) -> Repeat {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for Repeat {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
Expand Down Expand Up @@ -213,6 +215,7 @@ pub const fn sink() -> Sink {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand All @@ -237,6 +240,7 @@ impl Write for Sink {
}

#[stable(feature = "write_mt", since = "1.48.0")]
#[doc(notable_trait)]
impl Write for &Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ impl TcpStream {
// `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows.

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for TcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
Expand All @@ -629,6 +630,7 @@ impl Read for TcpStream {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
Expand All @@ -648,6 +650,7 @@ impl Write for TcpStream {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for &TcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
Expand All @@ -663,6 +666,7 @@ impl Read for &TcpStream {
}
}
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for &TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ pub struct ChildStdin {
// `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows.

#[stable(feature = "process", since = "1.0.0")]
#[doc(notable_trait)]
impl Write for ChildStdin {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&*self).write(buf)
Expand All @@ -285,6 +286,7 @@ impl Write for ChildStdin {
}

#[stable(feature = "write_mt", since = "1.48.0")]
#[doc(notable_trait)]
impl Write for &ChildStdin {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.write(buf)
Expand Down Expand Up @@ -349,6 +351,7 @@ pub struct ChildStdout {
// `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows.

#[stable(feature = "process", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for ChildStdout {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
Expand Down Expand Up @@ -414,6 +417,7 @@ pub struct ChildStderr {
// `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows.

#[stable(feature = "process", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for ChildStderr {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.read(buf)
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/formats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod item_type;
pub(crate) mod renderer;

use rustc_hir::def_id::DefId;
use rustc_span::sym;

pub(crate) use renderer::{run_format, FormatRenderer};

Expand Down Expand Up @@ -38,6 +39,10 @@ impl Impl {
}
}

pub(crate) fn is_notable(&self) -> bool {
self.impl_item.attrs.has_doc_flag(sym::notable_trait)
}

pub(crate) fn trait_did(&self) -> Option<DefId> {
self.inner_impl().trait_.as_ref().map(|t| t.def_id())
}
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
let trait_did = trait_.def_id();

if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx()))
|| i.is_notable()
{
has_notable_trait = true;
}
Expand Down

0 comments on commit 9055128

Please sign in to comment.