Skip to content

Commit 5662d93

Browse files
committed
Auto merge of #80965 - camelid:rename-doc-spotlight, r=jyn514
Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` Fixes #80936. "spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation r? `@Manishearth`
2 parents 4fa76a4 + 34c6cee commit 5662d93

File tree

23 files changed

+153
-88
lines changed

23 files changed

+153
-88
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
313313
include => external_doc
314314
cfg => doc_cfg
315315
masked => doc_masked
316-
spotlight => doc_spotlight
316+
notable_trait => doc_notable_trait
317317
keyword => doc_keyword
318318
);
319319
}

compiler/rustc_feature/src/active.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ declare_features! (
216216
/// Renamed from `optin_builtin_traits`.
217217
(active, auto_traits, "1.50.0", Some(13231), None),
218218

219+
/// Allows `#[doc(notable_trait)]`.
220+
/// Renamed from `doc_spotlight`.
221+
(active, doc_notable_trait, "1.52.0", Some(45040), None),
222+
219223
// no-tracking-issue-end
220224

221225
// -------------------------------------------------------------------------
@@ -374,9 +378,6 @@ declare_features! (
374378
/// Allows `#[doc(masked)]`.
375379
(active, doc_masked, "1.21.0", Some(44027), None),
376380

377-
/// Allows `#[doc(spotlight)]`.
378-
(active, doc_spotlight, "1.22.0", Some(45040), None),
379-
380381
/// Allows `#[doc(include = "some-file")]`.
381382
(active, external_doc, "1.22.0", Some(44732), None),
382383

compiler/rustc_feature/src/removed.rs

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ declare_features! (
8080
Some("subsumed by `#![feature(allocator_internals)]`")),
8181
/// Allows identifying crates that contain sanitizer runtimes.
8282
(removed, sanitizer_runtime, "1.17.0", None, None, None),
83+
/// Allows `#[doc(spotlight)]`.
84+
/// The attribute was renamed to `#[doc(notable_trait)]`
85+
/// and the feature to `doc_notable_trait`.
86+
(removed, doc_spotlight, "1.22.0", Some(45040), None,
87+
Some("renamed to `doc_notable_trait`")),
8388
(removed, proc_macro_mod, "1.27.0", Some(54727), None,
8489
Some("subsumed by `#![feature(proc_macro_hygiene)]`")),
8590
(removed, proc_macro_expr, "1.27.0", Some(54727), None,

compiler/rustc_passes/src/check_attr.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::query::Providers;
99
use rustc_middle::ty::TyCtxt;
1010

1111
use rustc_ast::{Attribute, Lit, LitKind, NestedMetaItem};
12-
use rustc_errors::{pluralize, struct_span_err};
12+
use rustc_errors::{pluralize, struct_span_err, Applicability};
1313
use rustc_hir as hir;
1414
use rustc_hir::def_id::LocalDefId;
1515
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -648,10 +648,10 @@ impl CheckAttrVisitor<'tcx> {
648648
| sym::masked
649649
| sym::no_default_passes
650650
| sym::no_inline
651+
| sym::notable_trait
651652
| sym::passes
652653
| sym::plugins
653654
| sym::primitive
654-
| sym::spotlight
655655
| sym::test => {}
656656

657657
_ => {
@@ -660,11 +660,23 @@ impl CheckAttrVisitor<'tcx> {
660660
hir_id,
661661
i_meta.span,
662662
|lint| {
663-
let msg = format!(
663+
let mut diag = lint.build(&format!(
664664
"unknown `doc` attribute `{}`",
665665
rustc_ast_pretty::pprust::path_to_string(&i_meta.path),
666-
);
667-
lint.build(&msg).emit();
666+
));
667+
if i_meta.has_name(sym::spotlight) {
668+
diag.note(
669+
"`doc(spotlight)` was renamed to `doc(notable_trait)`",
670+
);
671+
diag.span_suggestion_short(
672+
i_meta.span,
673+
"use `notable_trait` instead",
674+
String::from("notable_trait"),
675+
Applicability::MachineApplicable,
676+
);
677+
diag.note("`doc(spotlight)` is now a no-op");
678+
}
679+
diag.emit();
668680
},
669681
);
670682
is_valid = false;

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ symbols! {
477477
doc_cfg,
478478
doc_keyword,
479479
doc_masked,
480+
doc_notable_trait,
480481
doc_spotlight,
481482
doctest,
482483
document_private_items,
@@ -801,6 +802,7 @@ symbols! {
801802
noreturn,
802803
nostack,
803804
not,
805+
notable_trait,
804806
note,
805807
object_safe_for_dispatch,
806808
of,

library/core/src/future/future.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::task::{Context, Poll};
2424
/// `.await` the value.
2525
///
2626
/// [`Waker`]: crate::task::Waker
27-
#[doc(spotlight)]
27+
#[cfg_attr(bootstrap, doc(spotlight))]
28+
#[cfg_attr(not(bootstrap), doc(notable_trait))]
2829
#[must_use = "futures do nothing unless you `.await` or poll them"]
2930
#[stable(feature = "futures_api", since = "1.36.0")]
3031
#[lang = "future_trait"]

library/core/src/iter/traits/iterator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
9292
label = "`{Self}` is not an iterator",
9393
message = "`{Self}` is not an iterator"
9494
)]
95-
#[doc(spotlight)]
95+
#[cfg_attr(bootstrap, doc(spotlight))]
96+
#[cfg_attr(not(bootstrap), doc(notable_trait))]
9697
#[rustc_diagnostic_item = "Iterator"]
9798
#[must_use = "iterators are lazy and do nothing unless consumed"]
9899
pub trait Iterator {

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
#![feature(custom_inner_attributes)]
110110
#![feature(decl_macro)]
111111
#![feature(doc_cfg)]
112-
#![feature(doc_spotlight)]
112+
#![cfg_attr(bootstrap, feature(doc_spotlight))]
113+
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
113114
#![feature(duration_consts_2)]
114115
#![feature(duration_saturating_ops)]
115116
#![feature(extended_key_value_attributes)]

library/std/src/io/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
505505
/// [`std::io`]: self
506506
/// [`File`]: crate::fs::File
507507
#[stable(feature = "rust1", since = "1.0.0")]
508-
#[doc(spotlight)]
508+
#[cfg_attr(bootstrap, doc(spotlight))]
509+
#[cfg_attr(not(bootstrap), doc(notable_trait))]
509510
pub trait Read {
510511
/// Pull some bytes from this source into the specified buffer, returning
511512
/// how many bytes were read.
@@ -1296,7 +1297,8 @@ impl Initializer {
12961297
///
12971298
/// [`write_all`]: Write::write_all
12981299
#[stable(feature = "rust1", since = "1.0.0")]
1299-
#[doc(spotlight)]
1300+
#[cfg_attr(bootstrap, doc(spotlight))]
1301+
#[cfg_attr(not(bootstrap), doc(notable_trait))]
13001302
pub trait Write {
13011303
/// Write a buffer into this writer, returning how many bytes were written.
13021304
///

library/std/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@
257257
#![feature(doc_cfg)]
258258
#![feature(doc_keyword)]
259259
#![feature(doc_masked)]
260-
#![feature(doc_spotlight)]
260+
#![cfg_attr(bootstrap, feature(doc_spotlight))]
261+
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
261262
#![feature(dropck_eyepatch)]
262263
#![feature(duration_constants)]
263264
#![feature(duration_zero)]

src/doc/rustdoc/src/unstable-features.md

+22-20
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,28 @@ Book][unstable-doc-cfg] and [its tracking issue][issue-doc-cfg].
8888
[unstable-doc-cfg]: ../unstable-book/language-features/doc-cfg.html
8989
[issue-doc-cfg]: https://github.com/rust-lang/rust/issues/43781
9090

91-
### Adding your trait to the "Important Traits" dialog
92-
93-
Rustdoc keeps a list of a few traits that are believed to be "fundamental" to a given type when
94-
implemented on it. These traits are intended to be the primary interface for their types, and are
95-
often the only thing available to be documented on their types. For this reason, Rustdoc will track
96-
when a given type implements one of these traits and call special attention to it when a function
97-
returns one of these types. This is the "Important Traits" dialog, visible as a circle-i button next
98-
to the function, which, when clicked, shows the dialog.
99-
100-
In the standard library, the traits that qualify for inclusion are `Iterator`, `io::Read`, and
101-
`io::Write`. However, rather than being implemented as a hard-coded list, these traits have a
102-
special marker attribute on them: `#[doc(spotlight)]`. This means that you could apply this
103-
attribute to your own trait to include it in the "Important Traits" dialog in documentation.
104-
105-
The `#[doc(spotlight)]` attribute currently requires the `#![feature(doc_spotlight)]` feature gate.
106-
For more information, see [its chapter in the Unstable Book][unstable-spotlight] and [its tracking
107-
issue][issue-spotlight].
108-
109-
[unstable-spotlight]: ../unstable-book/language-features/doc-spotlight.html
110-
[issue-spotlight]: https://github.com/rust-lang/rust/issues/45040
91+
### Adding your trait to the "Notable traits" dialog
92+
93+
Rustdoc keeps a list of a few traits that are believed to be "fundamental" to
94+
types that implement them. These traits are intended to be the primary interface
95+
for their implementers, and are often most of the API available to be documented
96+
on their types. For this reason, Rustdoc will track when a given type implements
97+
one of these traits and call special attention to it when a function returns one
98+
of these types. This is the "Notable traits" dialog, accessible as a circled `i`
99+
button next to the function, which, when clicked, shows the dialog.
100+
101+
In the standard library, some of the traits that are part of this list are
102+
`Iterator`, `Future`, `io::Read`, and `io::Write`. However, rather than being
103+
implemented as a hard-coded list, these traits have a special marker attribute
104+
on them: `#[doc(notable_trait)]`. This means that you can apply this attribute
105+
to your own trait to include it in the "Notable traits" dialog in documentation.
106+
107+
The `#[doc(notable_trait)]` attribute currently requires the `#![feature(doc_notable_trait)]`
108+
feature gate. For more information, see [its chapter in the Unstable Book][unstable-notable_trait]
109+
and [its tracking issue][issue-notable_trait].
110+
111+
[unstable-notable_trait]: ../unstable-book/language-features/doc-notable-trait.html
112+
[issue-notable_trait]: https://github.com/rust-lang/rust/issues/45040
111113

112114
### Exclude certain dependencies from documentation
113115

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# `doc_notable_trait`
2+
3+
The tracking issue for this feature is: [#45040]
4+
5+
The `doc_notable_trait` feature allows the use of the `#[doc(notable_trait)]`
6+
attribute, which will display the trait in a "Notable traits" dialog for
7+
functions returning types that implement the trait. For example, this attribute
8+
is applied to the `Iterator`, `Future`, `io::Read`, and `io::Write` traits in
9+
the standard library.
10+
11+
You can do this on your own traits like so:
12+
13+
```
14+
#![feature(doc_notable_trait)]
15+
16+
#[doc(notable_trait)]
17+
pub trait MyTrait {}
18+
19+
pub struct MyStruct;
20+
impl MyTrait for MyStruct {}
21+
22+
/// The docs for this function will have a button that displays a dialog about
23+
/// `MyStruct` implementing `MyTrait`.
24+
pub fn my_fn() -> MyStruct { MyStruct }
25+
```
26+
27+
This feature was originally implemented in PR [#45039].
28+
29+
See also its documentation in [the rustdoc book][rustdoc-book-notable_trait].
30+
31+
[#45040]: https://github.com/rust-lang/rust/issues/45040
32+
[#45039]: https://github.com/rust-lang/rust/pull/45039
33+
[rustdoc-book-notable_trait]: ../../rustdoc/unstable-features.html#adding-your-trait-to-the-notable-traits-dialog

src/doc/unstable-book/src/language-features/doc-spotlight.md

-30
This file was deleted.

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
624624

625625
let trait_ = clean::TraitWithExtraInfo {
626626
trait_,
627-
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
627+
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::notable_trait),
628628
};
629629
cx.external_traits.borrow_mut().insert(did, trait_);
630630
cx.active_extern_traits.remove(&did);

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
227227
if let clean::TraitItem(ref t) = *item.kind {
228228
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
229229
trait_: t.clone(),
230-
is_spotlight: item.attrs.has_doc_flag(sym::spotlight),
230+
is_spotlight: item.attrs.has_doc_flag(sym::notable_trait),
231231
});
232232
}
233233

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ignore-tidy-linelength
2+
// check-pass
3+
// run-rustfix
4+
5+
#![feature(doc_notable_trait)]
6+
7+
#[doc(notable_trait)]
8+
//~^ WARN unknown `doc` attribute `spotlight`
9+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
10+
trait MyTrait {}

src/test/rustdoc-ui/doc-spotlight.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// ignore-tidy-linelength
2+
// check-pass
3+
// run-rustfix
4+
5+
#![feature(doc_notable_trait)]
6+
7+
#[doc(spotlight)]
8+
//~^ WARN unknown `doc` attribute `spotlight`
9+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
10+
trait MyTrait {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: unknown `doc` attribute `spotlight`
2+
--> $DIR/doc-spotlight.rs:7:7
3+
|
4+
LL | #[doc(spotlight)]
5+
| ^^^^^^^^^ help: use `notable_trait` instead
6+
|
7+
= note: `#[warn(invalid_doc_attributes)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
10+
= note: `doc(spotlight)` was renamed to `doc(notable_trait)`
11+
= note: `doc(spotlight)` is now a no-op
12+
13+
warning: 1 warning emitted
14+

src/test/rustdoc/doc-spotlight.rs src/test/rustdoc/doc-notable_trait.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#![feature(doc_spotlight)]
1+
#![feature(doc_notable_trait)]
22

33
pub struct Wrapper<T> {
44
inner: T,
55
}
66

77
impl<T: SomeTrait> SomeTrait for Wrapper<T> {}
88

9-
#[doc(spotlight)]
9+
#[doc(notable_trait)]
1010
pub trait SomeTrait {
11-
// @has doc_spotlight/trait.SomeTrait.html
11+
// @has doc_notable_trait/trait.SomeTrait.html
1212
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
1313
fn wrap_me(self) -> Wrapper<Self> where Self: Sized {
1414
Wrapper {
@@ -21,15 +21,15 @@ pub struct SomeStruct;
2121
impl SomeTrait for SomeStruct {}
2222

2323
impl SomeStruct {
24-
// @has doc_spotlight/struct.SomeStruct.html
24+
// @has doc_notable_trait/struct.SomeStruct.html
2525
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
2626
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
2727
pub fn new() -> SomeStruct {
2828
SomeStruct
2929
}
3030
}
3131

32-
// @has doc_spotlight/fn.bare_fn.html
32+
// @has doc_notable_trait/fn.bare_fn.html
3333
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
3434
pub fn bare_fn() -> SomeStruct {
3535
SomeStruct
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[doc(notable_trait)] //~ ERROR: `#[doc(notable_trait)]` is experimental
2+
trait SomeTrait {}
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: `#[doc(notable_trait)]` is experimental
2+
--> $DIR/feature-gate-doc_notable_trait.rs:1:1
3+
|
4+
LL | #[doc(notable_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #45040 <https://github.com/rust-lang/rust/issues/45040> for more information
8+
= help: add `#![feature(doc_notable_trait)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/feature-gates/feature-gate-doc_spotlight.rs

-4
This file was deleted.

0 commit comments

Comments
 (0)