Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(notable_trait) for impls #94904

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
notable trait for impls
  • Loading branch information
conradludgate committed Oct 17, 2023
commit 85766932cdd377814efcc0e5fb378f9857d913f1
1 change: 1 addition & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,7 @@ impl<'a> Formatter<'a> {
}

#[stable(since = "1.2.0", feature = "formatter_write")]
#[doc(notable_trait)]
impl Write for Formatter<'_> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if we decide to land this, I wonder if we should rename notable_trait to just notable...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense, since it'll cover notable_trait and notable_impl into one

Copy link

@Antikyth Antikyth Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it were to simply be called notable, I wonder if there would be usefulness in extending it to other areas too... notable fields? Is that useful? I don't know, but maybe it's worth exploring...

Perhaps notable items in e.g. a module would be useful. I have a module defining many structs and enums (100+) that doesn't make sense to split up, I wonder if notability is relevant to that or not.

fn write_str(&mut self, s: &str) -> Result {
self.buf.write_str(s)
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ fn buffer_capacity_required(mut file: &File) -> Option<usize> {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
impl Read for &File {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
Expand Down Expand Up @@ -784,6 +785,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 Expand Up @@ -811,6 +813,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).read(buf)
Expand All @@ -833,6 +836,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).write(buf)
Expand All @@ -857,6 +861,7 @@ impl Seek for File {
}

#[stable(feature = "io_traits_arc", since = "1.73.0")]
#[doc(notable_trait)]
impl Read for Arc<File> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&**self).read(buf)
Expand All @@ -879,6 +884,7 @@ impl Read for Arc<File> {
}
}
#[stable(feature = "io_traits_arc", since = "1.73.0")]
#[doc(notable_trait)]
impl Write for Arc<File> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&**self).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 @@ -608,7 +608,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 @@ -1457,7 +1456,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 @@ -418,6 +418,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 @@ -452,6 +453,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 @@ -677,6 +679,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 @@ -703,6 +706,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 @@ -729,6 +733,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 @@ -897,6 +902,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 @@ -923,6 +929,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 @@ -949,6 +956,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 @@ -57,6 +57,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 @@ -179,6 +180,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 @@ -272,6 +274,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 @@ -296,6 +299,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 @@ -633,6 +634,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 @@ -653,6 +655,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 @@ -672,6 +675,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 @@ -286,6 +287,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 @@ -352,6 +354,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 @@ -422,6 +425,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 @@ -1345,6 +1345,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