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

Rename #[doc(spotlight)] to #[doc(notable_trait)] #80965

Merged
merged 1 commit into from
Apr 2, 2021
Merged
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 @@ -313,7 +313,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
include => external_doc
cfg => doc_cfg
masked => doc_masked
spotlight => doc_spotlight
notable_trait => doc_notable_trait
keyword => doc_keyword
);
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ declare_features! (
/// Renamed from `optin_builtin_traits`.
(active, auto_traits, "1.50.0", Some(13231), None),

/// Allows `#[doc(notable_trait)]`.
/// Renamed from `doc_spotlight`.
(active, doc_notable_trait, "1.52.0", Some(45040), None),

// no-tracking-issue-end

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

/// Allows `#[doc(spotlight)]`.
(active, doc_spotlight, "1.22.0", Some(45040), None),

/// Allows `#[doc(include = "some-file")]`.
(active, external_doc, "1.22.0", Some(44732), None),

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ declare_features! (
Some("subsumed by `#![feature(allocator_internals)]`")),
/// Allows identifying crates that contain sanitizer runtimes.
(removed, sanitizer_runtime, "1.17.0", None, None, None),
/// Allows `#[doc(spotlight)]`.
/// The attribute was renamed to `#[doc(notable_trait)]`
/// and the feature to `doc_notable_trait`.
(removed, doc_spotlight, "1.22.0", Some(45040), None,
Some("renamed to `doc_notable_trait`")),
(removed, proc_macro_mod, "1.27.0", Some(54727), None,
Some("subsumed by `#![feature(proc_macro_hygiene)]`")),
(removed, proc_macro_expr, "1.27.0", Some(54727), None,
Expand Down
22 changes: 17 additions & 5 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;

use rustc_ast::{Attribute, Lit, LitKind, NestedMetaItem};
use rustc_errors::{pluralize, struct_span_err};
use rustc_errors::{pluralize, struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
Expand Down Expand Up @@ -589,10 +589,10 @@ impl CheckAttrVisitor<'tcx> {
| sym::masked
| sym::no_default_passes
| sym::no_inline
| sym::notable_trait
| sym::passes
| sym::plugins
| sym::primitive
| sym::spotlight
| sym::test => {}

_ => {
Expand All @@ -601,11 +601,23 @@ impl CheckAttrVisitor<'tcx> {
hir_id,
i_meta.span,
|lint| {
let msg = format!(
let mut diag = lint.build(&format!(
"unknown `doc` attribute `{}`",
rustc_ast_pretty::pprust::path_to_string(&i_meta.path),
);
lint.build(&msg).emit();
));
if i_meta.has_name(sym::spotlight) {
diag.note(
"`doc(spotlight)` was renamed to `doc(notable_trait)`",
);
diag.span_suggestion_short(
i_meta.span,
"use `notable_trait` instead",
String::from("notable_trait"),
Applicability::MachineApplicable,
);
diag.note("`doc(spotlight)` is now a no-op");
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be a warning?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, this seems fine.

}
diag.emit();
},
);
is_valid = false;
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ symbols! {
doc_cfg,
doc_keyword,
doc_masked,
doc_notable_trait,
doc_spotlight,
doctest,
document_private_items,
Expand Down Expand Up @@ -799,6 +800,7 @@ symbols! {
noreturn,
nostack,
not,
notable_trait,
note,
object_safe_for_dispatch,
of,
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use crate::task::{Context, Poll};
/// `.await` the value.
///
/// [`Waker`]: crate::task::Waker
#[doc(spotlight)]
#[cfg_attr(bootstrap, doc(spotlight))]
#[cfg_attr(not(bootstrap), doc(notable_trait))]
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[stable(feature = "futures_api", since = "1.36.0")]
#[lang = "future_trait"]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
label = "`{Self}` is not an iterator",
message = "`{Self}` is not an iterator"
)]
#[doc(spotlight)]
#[cfg_attr(bootstrap, doc(spotlight))]
#[cfg_attr(not(bootstrap), doc(notable_trait))]
#[rustc_diagnostic_item = "Iterator"]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub trait Iterator {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
#![feature(custom_inner_attributes)]
#![feature(decl_macro)]
#![feature(doc_cfg)]
#![feature(doc_spotlight)]
#![cfg_attr(bootstrap, feature(doc_spotlight))]
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
#![feature(duration_consts_2)]
#![feature(duration_saturating_ops)]
#![feature(extended_key_value_attributes)]
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
/// [`std::io`]: self
/// [`File`]: crate::fs::File
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(spotlight)]
#[cfg_attr(bootstrap, doc(spotlight))]
#[cfg_attr(not(bootstrap), doc(notable_trait))]
pub trait Read {
/// Pull some bytes from this source into the specified buffer, returning
/// how many bytes were read.
Expand Down Expand Up @@ -1291,7 +1292,8 @@ impl Initializer {
///
/// [`write_all`]: Write::write_all
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(spotlight)]
#[cfg_attr(bootstrap, doc(spotlight))]
#[cfg_attr(not(bootstrap), doc(notable_trait))]
pub trait Write {
/// Write a buffer into this writer, returning how many bytes were written.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
#![feature(doc_cfg)]
#![feature(doc_keyword)]
#![feature(doc_masked)]
#![feature(doc_spotlight)]
#![cfg_attr(bootstrap, feature(doc_spotlight))]
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
#![feature(dropck_eyepatch)]
#![feature(duration_constants)]
#![feature(duration_zero)]
Expand Down
42 changes: 22 additions & 20 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,28 @@ Book][unstable-doc-cfg] and [its tracking issue][issue-doc-cfg].
[unstable-doc-cfg]: ../unstable-book/language-features/doc-cfg.html
[issue-doc-cfg]: https://github.com/rust-lang/rust/issues/43781

### Adding your trait to the "Important Traits" dialog

Rustdoc keeps a list of a few traits that are believed to be "fundamental" to a given type when
implemented on it. These traits are intended to be the primary interface for their types, and are
often the only thing available to be documented on their types. For this reason, Rustdoc will track
when a given type implements one of these traits and call special attention to it when a function
returns one of these types. This is the "Important Traits" dialog, visible as a circle-i button next
to the function, which, when clicked, shows the dialog.

In the standard library, the traits that qualify for inclusion are `Iterator`, `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(spotlight)]`. This means that you could apply this
attribute to your own trait to include it in the "Important Traits" dialog in documentation.

The `#[doc(spotlight)]` attribute currently requires the `#![feature(doc_spotlight)]` feature gate.
For more information, see [its chapter in the Unstable Book][unstable-spotlight] and [its tracking
issue][issue-spotlight].

[unstable-spotlight]: ../unstable-book/language-features/doc-spotlight.html
[issue-spotlight]: https://github.com/rust-lang/rust/issues/45040
### Adding your trait to the "Notable traits" dialog

Rustdoc keeps a list of a few traits that are believed to be "fundamental" to
types that implement them. These traits are intended to be the primary interface
for their implementers, and are often most of the API available to be documented
on their types. For this reason, Rustdoc will track when a given type implements
one of these traits and call special attention to it when a function returns one
of these types. This is the "Notable traits" dialog, accessible as a circled `i`
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
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)]`
feature gate. For more information, see [its chapter in the Unstable Book][unstable-notable_trait]
and [its tracking issue][issue-notable_trait].

[unstable-notable_trait]: ../unstable-book/language-features/doc-notable-trait.html
[issue-notable_trait]: https://github.com/rust-lang/rust/issues/45040
Comment on lines +93 to +112
Copy link
Member

Choose a reason for hiding this comment

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

nit: is there a reason you rewrapped this? Did you change any of the text or just the wrapping?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did change the text; I changed mentions of "spotlight" to "notable trait", and I tweaked some of the wording. Sorry for the re-wrap, I know it's hard to review. I use gqap in Vim whenever I add text so that I don't end up with super long lines.

Here's the Git word-diff output, which should hopefully be easier to review:

diff --git a/old.md b/new.md
index 02a6f7b..92322be 100644
--- a/old.md
+++ b/new.md
@@ -1,20 +1,22 @@
### Adding your trait to the [-"Important Traits"-]{+"Notable traits"+} dialog

Rustdoc keeps a list of a few traits that are believed to be "fundamental" to
[-a given type when-]
[-implemented on it.-]{+types that implement them.+} These traits are intended to be the primary interface
for their [-types,-]{+implementers,+} and are often {+most of+} the [-only thing-]{+API+} available to be documented
on their types. For this reason, Rustdoc will track when a given type implements
one of these traits and call special attention to it when a function returns one
of these types. This is the [-"Important Traits"-]{+"Notable traits"+} dialog, [-visible-]{+accessible+} as a [-circle-i-]{+circled `i`+}
button next to the function, which, when clicked, shows the dialog.

In the standard library, {+some of+} the traits that [-qualify for inclusion-]{+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(spotlight)]`.-]{+`#[doc(notable_trait)]`.+} This means that you [-could-]{+can+} apply this attribute
to your own trait to include it in the [-"Important Traits"-]{+"Notable traits"+} dialog in documentation.

The [-`#[doc(spotlight)]`-]{+`#[doc(notable_trait)]`+} attribute currently requires the [-`#![feature(doc_spotlight)]`-]{+`#![feature(doc_notable_trait)]`+}
feature gate. For more information, see [its chapter in the Unstable [-Book][unstable-spotlight]-]{+Book][unstable-notable_trait]+}
and [its tracking [-issue][issue-spotlight].-]{+issue][issue-notable_trait].+}

[-[unstable-spotlight]: ../unstable-book/language-features/doc-spotlight.html-]
[-[issue-spotlight]:-]{+[unstable-notable_trait]: ../unstable-book/language-features/doc-notable-trait.html+}
{+[issue-notable_trait]:+} https://github.com/rust-lang/rust/issues/45040

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool, I am not sure all those changes are improvements but they at least don't seem strictly worse.


### Exclude certain dependencies from documentation

Expand Down
33 changes: 33 additions & 0 deletions src/doc/unstable-book/src/language-features/doc-notable-trait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# `doc_notable_trait`

The tracking issue for this feature is: [#45040]

The `doc_notable_trait` feature allows the use of the `#[doc(notable_trait)]`
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
the standard library.

You can do this on your own traits like so:

```
#![feature(doc_notable_trait)]

#[doc(notable_trait)]
pub trait MyTrait {}

pub struct MyStruct;
impl MyTrait for MyStruct {}

/// The docs for this function will have a button that displays a dialog about
/// `MyStruct` implementing `MyTrait`.
pub fn my_fn() -> MyStruct { MyStruct }
```

This feature was originally implemented in PR [#45039].

See also its documentation in [the rustdoc book][rustdoc-book-notable_trait].

[#45040]: https://github.com/rust-lang/rust/issues/45040
[#45039]: https://github.com/rust-lang/rust/pull/45039
[rustdoc-book-notable_trait]: ../../rustdoc/unstable-features.html#adding-your-trait-to-the-notable-traits-dialog
30 changes: 0 additions & 30 deletions src/doc/unstable-book/src/language-features/doc-spotlight.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {

let trait_ = clean::TraitWithExtraInfo {
trait_,
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::notable_trait),
};
cx.external_traits.borrow_mut().insert(did, trait_);
cx.active_extern_traits.remove(&did);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
if let clean::TraitItem(ref t) = *item.kind {
self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
trait_: t.clone(),
is_spotlight: item.attrs.has_doc_flag(sym::spotlight),
is_spotlight: item.attrs.has_doc_flag(sym::notable_trait),
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc-ui/doc-spotlight.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ignore-tidy-linelength
// check-pass
// run-rustfix

#![feature(doc_notable_trait)]

#[doc(notable_trait)]
//~^ WARN 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 {}
10 changes: 10 additions & 0 deletions src/test/rustdoc-ui/doc-spotlight.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ignore-tidy-linelength
// check-pass
// run-rustfix

#![feature(doc_notable_trait)]

#[doc(spotlight)]
//~^ WARN 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 {}
14 changes: 14 additions & 0 deletions src/test/rustdoc-ui/doc-spotlight.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning: unknown `doc` attribute `spotlight`
--> $DIR/doc-spotlight.rs:7:7
|
LL | #[doc(spotlight)]
| ^^^^^^^^^ help: use `notable_trait` instead
|
= note: `#[warn(invalid_doc_attributes)]` on by default
= 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 <https://github.com/rust-lang/rust/issues/82730>
= note: `doc(spotlight)` was renamed to `doc(notable_trait)`
= note: `doc(spotlight)` is now a no-op

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![feature(doc_spotlight)]
#![feature(doc_notable_trait)]

pub struct Wrapper<T> {
inner: T,
}

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

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

impl SomeStruct {
// @has doc_spotlight/struct.SomeStruct.html
// @has doc_notable_trait/struct.SomeStruct.html
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
pub fn new() -> SomeStruct {
SomeStruct
}
}

// @has doc_spotlight/fn.bare_fn.html
// @has doc_notable_trait/fn.bare_fn.html
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
pub fn bare_fn() -> SomeStruct {
SomeStruct
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-doc_notable_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[doc(notable_trait)] //~ ERROR: `#[doc(notable_trait)]` is experimental
trait SomeTrait {}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/feature-gates/feature-gate-doc_notable_trait.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0658]: `#[doc(notable_trait)]` is experimental
--> $DIR/feature-gate-doc_notable_trait.rs:1:1
|
LL | #[doc(notable_trait)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #45040 <https://github.com/rust-lang/rust/issues/45040> for more information
= help: add `#![feature(doc_notable_trait)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
4 changes: 0 additions & 4 deletions src/test/ui/feature-gates/feature-gate-doc_spotlight.rs

This file was deleted.

Loading