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 all commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
cfg => doc_cfg
cfg_hide => doc_cfg_hide
masked => doc_masked
notable_trait => doc_notable_trait
notable => doc_notable_trait
);

if nested_meta.has_name(sym::keyword) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ declare_features! (
(removed, doc_primitive, "1.56.0", Some(88070), None,
Some("merged into `#![feature(rustdoc_internals)]`")),
/// Allows `#[doc(spotlight)]`.
/// The attribute was renamed to `#[doc(notable_trait)]`
/// The attribute was renamed to `#[doc(notable)]`
/// and the feature to `doc_notable_trait`.
(removed, doc_spotlight, "1.22.0", Some(45040), None,
Some("renamed to `doc_notable_trait`")),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare_features! (
(unstable, auto_traits, "1.50.0", Some(13231), None),
/// Allows using `box` in patterns (RFC 469).
(unstable, box_patterns, "1.0.0", Some(29641), None),
/// Allows `#[doc(notable_trait)]`.
/// Allows `#[doc(notable)]`.
/// Renamed from `doc_spotlight`.
(unstable, doc_notable_trait, "1.52.0", Some(45040), None),
/// Allows using the `may_dangle` attribute (RFC 1327).
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,9 @@ rustc_queries! {
separate_provide_extern
}

/// Determines whether an item is annotated with `doc(notable_trait)`.
query is_doc_notable_trait(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
/// Determines whether an item is annotated with `doc(notable)`.
query is_doc_notable(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` is `doc(notable)`", tcx.def_path_str(def_id) }
}

/// Returns the attributes on the item at `def_id`.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,11 +1432,11 @@ fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
}

/// Determines whether an item is annotated with `doc(notable_trait)`.
pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
/// Determines whether an item is annotated with `doc(notable)`.
pub fn is_doc_notable(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
tcx.get_attrs(def_id, sym::doc)
.filter_map(|attr| attr.meta_item_list())
.any(|items| items.iter().any(|item| item.has_name(sym::notable_trait)))
.any(|items| items.iter().any(|item| item.has_name(sym::notable)))
}

/// Determines whether an item is an intrinsic by Abi.
Expand All @@ -1448,7 +1448,7 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers {
reveal_opaque_types_in_bounds,
is_doc_hidden,
is_doc_notable_trait,
is_doc_notable,
is_intrinsic,
..*providers
}
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,16 @@ passes_doc_test_unknown_include =
unknown `doc` attribute `{$path}`
.suggestion = use `doc = include_str!` instead

passes_doc_test_unknown_notable_trait =
unknown `doc` attribute `{$path}`
.note = `doc(notable_trait)` was renamed to `doc(notable)`
.suggestion = use `notable` instead
.no_op_note = `doc(notable_trait)` is now a no-op

passes_doc_test_unknown_spotlight =
unknown `doc` attribute `{$path}`
.note = `doc(spotlight)` was renamed to `doc(notable_trait)`
.suggestion = use `notable_trait` instead
.note = `doc(spotlight)` was renamed to `doc(notable)`
.suggestion = use `notable` instead
.no_op_note = `doc(spotlight)` is now a no-op

passes_duplicate_diagnostic_item_in_crate =
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ impl CheckAttrVisitor<'_> {
| sym::masked
| sym::no_default_passes
| sym::no_inline
| sym::notable_trait
| sym::notable
| sym::passes
| sym::plugins
| sym::fake_variadic => {}
Expand Down Expand Up @@ -1189,6 +1189,13 @@ impl CheckAttrVisitor<'_> {
i_meta.span,
errors::DocTestUnknownSpotlight { path, span: i_meta.span },
);
} else if i_meta.has_name(sym::notable_trait) {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
errors::DocTestUnknownNotableTrait { path, span: i_meta.span },
);
} else if i_meta.has_name(sym::include)
&& let Some(value) = i_meta.value_str()
{
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,23 @@ pub struct DocTestUnknownAny {
pub path: String,
}

#[derive(LintDiagnostic)]
#[diag(passes_doc_test_unknown_notable_trait)]
#[note]
#[note(passes_no_op_note)]
pub struct DocTestUnknownNotableTrait {
pub path: String,
#[suggestion(style = "short", applicability = "machine-applicable", code = "notable")]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes_doc_test_unknown_spotlight)]
#[note]
#[note(passes_no_op_note)]
pub struct DocTestUnknownSpotlight {
pub path: String,
#[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
#[suggestion(style = "short", applicability = "machine-applicable", code = "notable")]
pub span: Span,
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ symbols! {
noreturn,
nostack,
not,
notable,
notable_trait,
note,
object_safe_for_dispatch,
Expand Down
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
impl Write for Formatter<'_> {
fn write_str(&mut self, s: &str) -> Result {
self.buf.write_str(s)
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::task::{Context, Poll};
///
/// [`async`]: ../../std/keyword.async.html
/// [`Waker`]: crate::task::Waker
#[doc(notable_trait)]
#[cfg_attr(not(bootstrap), doc(notable))]
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[stable(feature = "futures_api", since = "1.36.0")]
#[lang = "future_trait"]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
label = "`{Self}` is not an iterator",
message = "`{Self}` is not an iterator"
)]
#[doc(notable_trait)]
#[cfg_attr(not(bootstrap), doc(notable))]
#[rustc_diagnostic_item = "Iterator"]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub trait Iterator {
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
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")]
#[cfg_attr(not(bootstrap), doc(notable))]
impl Write for &TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
Expand Down
Loading