diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 9328b83e8f3b0..cde7063ebea2d 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -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) { diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 339f596144c94..d5324c03803dc 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -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`")), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 27cdf1ba8316e..e266715f5d51c 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -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). diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 340c5a769dbc4..503d0ae50cfbf 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -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`. diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 31b52677b2797..1cf916f7e1b3f 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -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. @@ -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 } diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 25ef5245cf169..7111c672d1043 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -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 = diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 8b408d8202eb7..d48429ea47ca7 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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 => {} @@ -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() { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index a4397ceeb8cc9..0b95212de6dbe 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -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, } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index ea261923c6541..7b27639b2cec8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1097,6 +1097,7 @@ symbols! { noreturn, nostack, not, + notable, notable_trait, note, object_safe_for_dispatch, diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 98aa77fb5a79a..b6b0cb667fb7a 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2260,7 +2260,7 @@ impl<'a> Formatter<'a> { } #[stable(since = "1.2.0", feature = "formatter_write")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Formatter<'_> { fn write_str(&mut self, s: &str) -> Result { self.buf.write_str(s) diff --git a/library/core/src/future/future.rs b/library/core/src/future/future.rs index 8c7111cb3ff0b..5f83feae7753d 100644 --- a/library/core/src/future/future.rs +++ b/library/core/src/future/future.rs @@ -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"] diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index c7ace58afa866..80f240d9469c5 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -68,7 +68,7 @@ fn _assert_is_object_safe(_: &dyn Iterator) {} 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 { diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index fb41365bfc047..fb3399c075822 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -748,7 +748,7 @@ fn buffer_capacity_required(mut file: &File) -> Option { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for &File { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result { @@ -785,7 +785,7 @@ impl Read for &File { } } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &File { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.write(buf) @@ -813,7 +813,7 @@ impl Seek for &File { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for File { fn read(&mut self, buf: &mut [u8]) -> io::Result { (&*self).read(buf) @@ -836,7 +836,7 @@ impl Read for File { } } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for File { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -861,7 +861,7 @@ impl Seek for File { } #[stable(feature = "io_traits_arc", since = "1.73.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for Arc { fn read(&mut self, buf: &mut [u8]) -> io::Result { (&**self).read(buf) @@ -884,7 +884,7 @@ impl Read for Arc { } } #[stable(feature = "io_traits_arc", since = "1.73.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Arc { fn write(&mut self, buf: &[u8]) -> io::Result { (&**self).write(buf) diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index bab971a62fcc5..3179ea575ec49 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -520,7 +520,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Cursor<&mut [u8]> { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -544,7 +544,7 @@ impl Write for Cursor<&mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Cursor<&mut Vec> where A: Allocator, @@ -569,7 +569,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Cursor> where A: Allocator, @@ -594,7 +594,7 @@ where } #[stable(feature = "cursor_box_slice", since = "1.5.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Cursor> where A: Allocator, @@ -621,7 +621,7 @@ where } #[stable(feature = "cursor_array", since = "1.61.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Cursor<[u8; N]> { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 7c2bcee9ae19f..0c41bc6c1cb2e 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -418,7 +418,7 @@ impl fmt::Debug for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) @@ -453,7 +453,7 @@ impl StdinLock<'_> { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for StdinLock<'_> { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.inner.read(buf) @@ -679,7 +679,7 @@ impl fmt::Debug for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -706,7 +706,7 @@ impl Write for Stdout { } #[stable(feature = "write_mt", since = "1.48.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -733,7 +733,7 @@ impl Write for &Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -902,7 +902,7 @@ impl fmt::Debug for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -929,7 +929,7 @@ impl Write for Stderr { } #[stable(feature = "write_mt", since = "1.48.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -956,7 +956,7 @@ impl Write for &Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index ebd5490f289bd..7a8b6aeaed1d1 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -57,7 +57,7 @@ pub const fn empty() -> Empty { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for Empty { #[inline] fn read(&mut self, _buf: &mut [u8]) -> io::Result { @@ -180,7 +180,7 @@ pub const fn repeat(byte: u8) -> Repeat { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for Repeat { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result { @@ -274,7 +274,7 @@ pub const fn sink() -> Sink { } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for Sink { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -299,7 +299,7 @@ impl Write for Sink { } #[stable(feature = "write_mt", since = "1.48.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &Sink { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index e71fdf3f16d13..b146d3f8a8e74 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -614,7 +614,7 @@ impl TcpStream { // `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) @@ -634,7 +634,7 @@ impl Read for TcpStream { } } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) @@ -655,7 +655,7 @@ impl Write for TcpStream { } } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for &TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) @@ -675,7 +675,7 @@ impl Read for &TcpStream { } } #[stable(feature = "rust1", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 2f2641bd23e42..162d34a21cd1c 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -266,7 +266,7 @@ pub struct ChildStdin { // `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows. #[stable(feature = "process", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for ChildStdin { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -287,7 +287,7 @@ impl Write for ChildStdin { } #[stable(feature = "write_mt", since = "1.48.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Write for &ChildStdin { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.write(buf) @@ -354,7 +354,7 @@ pub struct ChildStdout { // `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows. #[stable(feature = "process", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for ChildStdout { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.inner.read(buf) @@ -425,7 +425,7 @@ pub struct ChildStderr { // `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows. #[stable(feature = "process", since = "1.0.0")] -#[doc(notable_trait)] +#[cfg_attr(not(bootstrap), doc(notable))] impl Read for ChildStderr { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.inner.read(buf) diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 199b5d69a1c7c..e8625bb6849d0 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -149,10 +149,10 @@ button next to the function, which, when clicked, shows the dialog. In the standard library, some of the traits that are part of this list are `Iterator`, `Future`, `io::Read`, and `io::Write`. However, rather than being implemented as a hard-coded list, these traits have a special marker attribute -on them: `#[doc(notable_trait)]`. This means that you can apply this attribute +on them: `#[doc(notable)]`. This means that you can apply this attribute to your own trait to include it in the "Notable traits" dialog in documentation. -The `#[doc(notable_trait)]` attribute currently requires the `#![feature(doc_notable_trait)]` +The `#[doc(notable)]` attribute currently requires the `#![feature(doc_notable_trait)]` feature gate. For more information, see [its chapter in the Unstable Book][unstable-notable_trait] and [its tracking issue][issue-notable_trait]. diff --git a/src/doc/unstable-book/src/language-features/doc-notable-trait.md b/src/doc/unstable-book/src/language-features/doc-notable-trait.md index dc402ed4253ac..ed34ff22e295c 100644 --- a/src/doc/unstable-book/src/language-features/doc-notable-trait.md +++ b/src/doc/unstable-book/src/language-features/doc-notable-trait.md @@ -2,7 +2,7 @@ The tracking issue for this feature is: [#45040] -The `doc_notable_trait` feature allows the use of the `#[doc(notable_trait)]` +The `doc_notable_trait` feature allows the use of the `#[doc(notable)]` attribute, which will display the trait in a "Notable traits" dialog for functions returning types that implement the trait. For example, this attribute is applied to the `Iterator`, `Future`, `io::Read`, and `io::Write` traits in @@ -13,7 +13,7 @@ You can do this on your own traits like so: ``` #![feature(doc_notable_trait)] -#[doc(notable_trait)] +#[doc(notable)] pub trait MyTrait {} pub struct MyStruct; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2a54266676d0c..33a46db6e4618 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1449,8 +1449,8 @@ impl Trait { pub(crate) fn is_auto(&self, tcx: TyCtxt<'_>) -> bool { tcx.trait_is_auto(self.def_id) } - pub(crate) fn is_notable_trait(&self, tcx: TyCtxt<'_>) -> bool { - tcx.is_doc_notable_trait(self.def_id) + pub(crate) fn is_notable(&self, tcx: TyCtxt<'_>) -> bool { + tcx.is_doc_notable(self.def_id) } pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety { tcx.trait_def(self.def_id).unsafety diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs index da82154131f92..f263a780d8738 100644 --- a/src/librustdoc/formats/mod.rs +++ b/src/librustdoc/formats/mod.rs @@ -40,7 +40,7 @@ impl Impl { } pub(crate) fn is_notable(&self) -> bool { - self.impl_item.attrs.has_doc_flag(sym::notable_trait) + self.impl_item.attrs.has_doc_flag(sym::notable) } pub(crate) fn trait_did(&self) -> Option { diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index bf8d1a80337e8..fd3fd8d1f8f4c 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -75,7 +75,7 @@ pub(crate) struct Context<'tcx> { /// `true`. pub(crate) include_sources: bool, /// Collection of all types with notable traits referenced in the current module. - pub(crate) types_with_notable_traits: FxHashSet, + pub(crate) types_with_notables: FxHashSet, /// Field used during rendering, to know if we're inside an inlined item. pub(crate) is_inside_inlined_module: bool, } @@ -613,7 +613,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { deref_id_map: Default::default(), shared: Rc::new(scx), include_sources, - types_with_notable_traits: FxHashSet::default(), + types_with_notables: FxHashSet::default(), is_inside_inlined_module: false, }; @@ -643,7 +643,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { id_map: IdMap::new(), shared: Rc::clone(&self.shared), include_sources: self.include_sources, - types_with_notable_traits: FxHashSet::default(), + types_with_notables: FxHashSet::default(), is_inside_inlined_module: self.is_inside_inlined_module, } } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index b3119941a4ad2..0d0578282e655 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -863,7 +863,7 @@ fn assoc_method( + name.as_str().len() + generics_len; - let notable_traits = notable_traits_button(&d.output, cx); + let notables = notables_button(&d.output, cx); let (indent, indent_str, end_newline) = if parent == ItemType::Trait { header_len += 4; @@ -878,7 +878,7 @@ fn assoc_method( write!( w, "{indent}{vis}{defaultness}{constness}{asyncness}{unsafety}{abi}fn \ - {name}{generics}{decl}{notable_traits}{where_clause}", + {name}{generics}{decl}{notables}{where_clause}", indent = indent_str, vis = vis, defaultness = defaultness, @@ -890,7 +890,7 @@ fn assoc_method( name = name, generics = g.print(cx), decl = d.full_print(header_len, indent, cx), - notable_traits = notable_traits.unwrap_or_default(), + notables = notables.unwrap_or_default(), where_clause = print_where_clause(g, cx, indent, end_newline), ); } @@ -1313,8 +1313,8 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) -> } } -pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> Option { - let mut has_notable_trait = false; +pub(crate) fn notables_button(ty: &clean::Type, cx: &mut Context<'_>) -> Option { + let mut has_notable = false; if ty.is_unit() { // Very common fast path. @@ -1344,17 +1344,17 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O if let Some(trait_) = &impl_.trait_ { let trait_did = trait_.def_id(); - if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx())) + if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable(cx.tcx())) || i.is_notable() { - has_notable_trait = true; + has_notable = true; } } } } - if has_notable_trait { - cx.types_with_notable_traits.insert(ty.clone()); + if has_notable { + cx.types_with_notables.insert(ty.clone()); Some(format!( " ", ty = Escape(&format!("{:#}", ty.print(cx))), @@ -1364,12 +1364,12 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O } } -fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { +fn notables_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { let mut out = Buffer::html(); - let did = ty.def_id(cx.cache()).expect("notable_traits_button already checked this"); + let did = ty.def_id(cx.cache()).expect("notables_button already checked this"); - let impls = cx.cache().impls.get(&did).expect("notable_traits_button already checked this"); + let impls = cx.cache().impls.get(&did).expect("notables_button already checked this"); for i in impls { let impl_ = i.inner_impl(); @@ -1381,7 +1381,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { if let Some(trait_) = &impl_.trait_ { let trait_did = trait_.def_id(); - if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx())) { + if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable(cx.tcx())) { if out.is_empty() { write!( &mut out, @@ -1425,11 +1425,11 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { (format!("{:#}", ty.print(cx)), out.into_inner()) } -pub(crate) fn notable_traits_json<'a>( +pub(crate) fn notables_json<'a>( tys: impl Iterator, cx: &Context<'_>, ) -> String { - let mut mp: Vec<(String, String)> = tys.map(|ty| notable_traits_decl(ty, cx)).collect(); + let mut mp: Vec<(String, String)> = tys.map(|ty| notables_decl(ty, cx)).collect(); mp.sort_by(|(name1, _html1), (name2, _html2)| name1.cmp(name2)); struct NotableTraitsMap(Vec<(String, String)>); impl Serialize for NotableTraitsMap { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index f6432dc61ae06..91a8078faaec8 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -20,10 +20,10 @@ use std::rc::Rc; use super::type_layout::document_type_layout; use super::{ collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference, - item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls, - render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre, - render_impl, render_rightside, render_stability_since_raw, - render_stability_since_raw_with_extra, AssocItemLink, Context, ImplRenderingParameters, + item_ty_to_section, notables_button, notables_json, render_all_impls, render_assoc_item, + render_assoc_items, render_attributes_in_code, render_attributes_in_pre, render_impl, + render_rightside, render_stability_since_raw, render_stability_since_raw_with_extra, + AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean; use crate::config::ModuleSorting; @@ -292,13 +292,13 @@ pub(super) fn print_item( } // Render notable-traits.js used for all methods in this module. - if !cx.types_with_notable_traits.is_empty() { + if !cx.types_with_notables.is_empty() { write!( buf, r#""#, - notable_traits_json(cx.types_with_notable_traits.iter(), cx) + notables_json(cx.types_with_notables.iter(), cx) ); - cx.types_with_notable_traits.clear(); + cx.types_with_notables.clear(); } } @@ -650,14 +650,14 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle + name.as_str().len() + generics_len; - let notable_traits = notable_traits_button(&f.decl.output, cx); + let notables = notables_button(&f.decl.output, cx); wrap_item(w, |w| { w.reserve(header_len); write!( w, "{attrs}{vis}{constness}{asyncness}{unsafety}{abi}fn \ - {name}{generics}{decl}{notable_traits}{where_clause}", + {name}{generics}{decl}{notables}{where_clause}", attrs = render_attributes_in_pre(it, "", cx), vis = visibility, constness = constness, @@ -668,7 +668,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle generics = f.generics.print(cx), where_clause = print_where_clause(&f.generics, cx, 0, Ending::Newline), decl = f.decl.full_print(header_len, 0, cx), - notable_traits = notable_traits.unwrap_or_default(), + notables = notables.unwrap_or_default(), ); }); write!(w, "{}", document(cx, it, None, HeadingOffset::H2)); diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 2e9897ef82ba2..734e4181e6ccf 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -835,10 +835,10 @@ function preLoadCss(cssUrl) { */ function showTooltip(e) { const notable_ty = e.getAttribute("data-notable-ty"); - if (!window.NOTABLE_TRAITS && notable_ty) { + if (!window.notableS && notable_ty) { const data = document.getElementById("notable-traits-data"); if (data) { - window.NOTABLE_TRAITS = JSON.parse(data.innerText); + window.notableS = JSON.parse(data.innerText); } else { throw new Error("showTooltip() called with notable without any notable traits!"); } @@ -853,7 +853,7 @@ function preLoadCss(cssUrl) { const wrapper = document.createElement("div"); if (notable_ty) { wrapper.innerHTML = "
" + - window.NOTABLE_TRAITS[notable_ty] + "
"; + window.notableS[notable_ty] + ""; } else { // Replace any `title` attribute with `data-title` to avoid double tooltips. if (e.getAttribute("title") !== null) { diff --git a/tests/rustdoc-ui/lints/doc-notable-trait.fixed b/tests/rustdoc-ui/lints/doc-notable-trait.fixed new file mode 100644 index 0000000000000..a88dff8f3a656 --- /dev/null +++ b/tests/rustdoc-ui/lints/doc-notable-trait.fixed @@ -0,0 +1,8 @@ +// run-rustfix +#![deny(warnings)] +#![feature(doc_notable_trait)] + +#[doc(notable)] +//~^ ERROR unknown `doc` attribute `spotlight` +//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +trait MyTrait {} diff --git a/tests/rustdoc-ui/lints/doc-notable-trait.rs b/tests/rustdoc-ui/lints/doc-notable-trait.rs new file mode 100644 index 0000000000000..16e387245802b --- /dev/null +++ b/tests/rustdoc-ui/lints/doc-notable-trait.rs @@ -0,0 +1,8 @@ +// run-rustfix +#![deny(warnings)] +#![feature(doc_notable_trait)] + +#[doc(spotlight)] +//~^ ERROR unknown `doc` attribute `spotlight` +//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +trait MyTrait {} diff --git a/tests/rustdoc-ui/lints/doc-notable-trait.stderr b/tests/rustdoc-ui/lints/doc-notable-trait.stderr new file mode 100644 index 0000000000000..ca06aed7b65e1 --- /dev/null +++ b/tests/rustdoc-ui/lints/doc-notable-trait.stderr @@ -0,0 +1,19 @@ +error: unknown `doc` attribute `notable_trait` + --> $DIR/doc-spotlight.rs:5:7 + | +LL | #[doc(notable_trait)] + | ^^^^^^^^^ help: use `notable` instead + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82730 + = note: `doc(notable_trait)` was renamed to `doc(notable)` + = note: `doc(notable_trait)` is now a no-op +note: the lint level is defined here + --> $DIR/doc-notable-trait.rs:2:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]` + +error: aborting due to previous error + diff --git a/tests/rustdoc-ui/lints/doc-spotlight.fixed b/tests/rustdoc-ui/lints/doc-spotlight.fixed index 4b58778eacd17..a88dff8f3a656 100644 --- a/tests/rustdoc-ui/lints/doc-spotlight.fixed +++ b/tests/rustdoc-ui/lints/doc-spotlight.fixed @@ -2,7 +2,7 @@ #![deny(warnings)] #![feature(doc_notable_trait)] -#[doc(notable_trait)] +#[doc(notable)] //~^ ERROR unknown `doc` attribute `spotlight` //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! trait MyTrait {} diff --git a/tests/rustdoc-ui/lints/doc-spotlight.stderr b/tests/rustdoc-ui/lints/doc-spotlight.stderr index 58612327ff93e..e2efade875815 100644 --- a/tests/rustdoc-ui/lints/doc-spotlight.stderr +++ b/tests/rustdoc-ui/lints/doc-spotlight.stderr @@ -2,11 +2,11 @@ error: unknown `doc` attribute `spotlight` --> $DIR/doc-spotlight.rs:5:7 | LL | #[doc(spotlight)] - | ^^^^^^^^^ help: use `notable_trait` instead + | ^^^^^^^^^ help: use `notable` instead | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #82730 - = note: `doc(spotlight)` was renamed to `doc(notable_trait)` + = note: `doc(spotlight)` was renamed to `doc(notable)` = note: `doc(spotlight)` is now a no-op note: the lint level is defined here --> $DIR/doc-spotlight.rs:2:9 diff --git a/tests/rustdoc/notable-trait/doc-notable_trait-slice.bare_fn_matches.html b/tests/rustdoc/notable-trait/doc-notable_trait-slice.bare_fn_matches.html index 46be00a080482..cea6666565cdc 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait-slice.bare_fn_matches.html +++ b/tests/rustdoc/notable-trait/doc-notable_trait-slice.bare_fn_matches.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/rustdoc/notable-trait/doc-notable_trait-slice.rs b/tests/rustdoc/notable-trait/doc-notable_trait-slice.rs index ef206710b4b08..aa9a357a0a367 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait-slice.rs +++ b/tests/rustdoc/notable-trait/doc-notable_trait-slice.rs @@ -1,6 +1,6 @@ #![feature(doc_notable_trait)] -#[doc(notable_trait)] +#[doc(notable)] pub trait SomeTrait {} pub struct SomeStruct; diff --git a/tests/rustdoc/notable-trait/doc-notable_trait.bare-fn.html b/tests/rustdoc/notable-trait/doc-notable_trait.bare-fn.html index f592e3b375c02..6241eb144675a 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait.bare-fn.html +++ b/tests/rustdoc/notable-trait/doc-notable_trait.bare-fn.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/rustdoc/notable-trait/doc-notable_trait.rs b/tests/rustdoc/notable-trait/doc-notable_trait.rs index d8941769fa67a..9413362b69233 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait.rs +++ b/tests/rustdoc/notable-trait/doc-notable_trait.rs @@ -6,7 +6,7 @@ pub struct Wrapper { impl SomeTrait for Wrapper {} -#[doc(notable_trait)] +#[doc(notable)] pub trait SomeTrait { // @has doc_notable_trait/trait.SomeTrait.html // @has - '//a[@class="tooltip"]/@data-notable-ty' 'Wrapper' diff --git a/tests/rustdoc/notable-trait/doc-notable_trait.some-struct-new.html b/tests/rustdoc/notable-trait/doc-notable_trait.some-struct-new.html index e8f4f6000457d..0a7217e6d98a6 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait.some-struct-new.html +++ b/tests/rustdoc/notable-trait/doc-notable_trait.some-struct-new.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/rustdoc/notable-trait/doc-notable_trait.wrap-me.html b/tests/rustdoc/notable-trait/doc-notable_trait.wrap-me.html index e7909669b150a..a5c46037db94d 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait.wrap-me.html +++ b/tests/rustdoc/notable-trait/doc-notable_trait.wrap-me.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/rustdoc/notable-trait/doc-notable_trait_box_is_not_an_iterator.rs b/tests/rustdoc/notable-trait/doc-notable_trait_box_is_not_an_iterator.rs index 3fb00c7db8411..b4e18c85f738b 100644 --- a/tests/rustdoc/notable-trait/doc-notable_trait_box_is_not_an_iterator.rs +++ b/tests/rustdoc/notable-trait/doc-notable_trait_box_is_not_an_iterator.rs @@ -11,7 +11,7 @@ impl Box { } } -#[doc(notable_trait)] +#[doc(notable)] pub trait FakeIterator {} impl FakeIterator for Box {} diff --git a/tests/rustdoc/notable-trait/notable-trait-generics.rs b/tests/rustdoc/notable-trait/notable-trait-generics.rs index 611902abad65b..4c23f53f47d74 100644 --- a/tests/rustdoc/notable-trait/notable-trait-generics.rs +++ b/tests/rustdoc/notable-trait/notable-trait-generics.rs @@ -5,7 +5,7 @@ pub mod generic_return { pub struct Wrapper(T); - #[doc(notable_trait)] + #[doc(notable)] pub trait NotableTrait {} impl NotableTrait for Wrapper {} @@ -22,7 +22,7 @@ pub mod generic_return { pub mod generic_impl { pub struct Wrapper(T); - #[doc(notable_trait)] + #[doc(notable)] pub trait NotableTrait {} impl NotableTrait for Wrapper {} diff --git a/tests/ui/feature-gates/feature-gate-doc_notable_trait.rs b/tests/ui/feature-gates/feature-gate-doc_notable_trait.rs index 7f3392eadadb3..c24e3d67a419e 100644 --- a/tests/ui/feature-gates/feature-gate-doc_notable_trait.rs +++ b/tests/ui/feature-gates/feature-gate-doc_notable_trait.rs @@ -1,4 +1,4 @@ -#[doc(notable_trait)] //~ ERROR: `#[doc(notable_trait)]` is experimental +#[doc(notable)] //~ ERROR: `#[doc(notable)]` is experimental trait SomeTrait {} fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-doc_notable_trait.stderr b/tests/ui/feature-gates/feature-gate-doc_notable_trait.stderr index 1f9bef40c4e73..492be9817b15f 100644 --- a/tests/ui/feature-gates/feature-gate-doc_notable_trait.stderr +++ b/tests/ui/feature-gates/feature-gate-doc_notable_trait.stderr @@ -1,8 +1,8 @@ -error[E0658]: `#[doc(notable_trait)]` is experimental +error[E0658]: `#[doc(notable)]` is experimental --> $DIR/feature-gate-doc_notable_trait.rs:1:1 | -LL | #[doc(notable_trait)] - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #[doc(notable)] + | ^^^^^^^^^^^^^^^ | = note: see issue #45040 for more information = help: add `#![feature(doc_notable_trait)]` to the crate attributes to enable