Skip to content

Commit

Permalink
Rollup merge of rust-lang#90420 - GuillaumeGomez:rustdoc-internals-fe…
Browse files Browse the repository at this point in the history
…ature, r=camelid

Create rustdoc_internals feature gate

As suggested by ``@camelid`` [here](rust-lang#90398 (comment)), since `doc_keyword` and `doc_primitive` aren't meant to be stabilized, we could put them behind a same feature flag.

This is pretty much what it would look like (needs to update the tests too).

The tracking issue is rust-lang#90418.

What do you think ``@rust-lang/rustdoc`` ?
  • Loading branch information
GuillaumeGomez authored Nov 24, 2021
2 parents cbe563a + 9447d1f commit a6a1d7c
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 37 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
cfg_hide => doc_cfg_hide
masked => doc_masked
notable_trait => doc_notable_trait
keyword => doc_keyword
);

if nested_meta.has_name(sym::keyword) {
let msg = "`#[doc(keyword)]` is meant for internal use only";
gate_feature_post!(self, rustdoc_internals, attr.span, msg);
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ declare_features! (
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
/// Allows using compiler's own crates.
(active, rustc_private, "1.0.0", Some(27812), None),
/// Allows using internal rustdoc features like `doc(primitive)` or `doc(keyword)`.
(active, rustdoc_internals, "1.58.0", Some(90418), None),
/// Allows using `#[start]` on a function indicating that it is the program entrypoint.
(active, start, "1.0.0", Some(29633), None),
/// Allows using `#[structural_match]` which indicates that a type is structurally matchable.
Expand Down Expand Up @@ -366,12 +368,8 @@ declare_features! (
(active, doc_cfg, "1.21.0", Some(43781), None),
/// Allows `#[doc(cfg_hide(...))]`.
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
/// Allows using `#[doc(keyword = "...")]`.
(active, doc_keyword, "1.28.0", Some(51315), None),
/// Allows `#[doc(masked)]`.
(active, doc_masked, "1.21.0", Some(44027), None),
/// Allows using doc(primitive) without a future-incompat warning
(active, doc_primitive, "1.56.0", Some(88070), None),
/// Allows `X..Y` patterns.
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ declare_features! (
/// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
(removed, custom_derive, "1.32.0", Some(29644), None,
Some("subsumed by `#[proc_macro_derive]`")),
/// Allows using `#[doc(keyword = "...")]`.
(removed, doc_keyword, "1.28.0", Some(51315), None,
Some("merged into `#![feature(rustdoc_internals)]`")),
/// Allows using `doc(primitive)` without a future-incompat warning.
(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)]`
/// and the feature to `doc_notable_trait`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ impl CheckAttrVisitor<'tcx> {
}

sym::primitive => {
if !self.tcx.features().doc_primitive {
if !self.tcx.features().rustdoc_internals {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
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 @@ -1155,6 +1155,7 @@ symbols! {
rustc_unsafe_specialization_marker,
rustc_variance,
rustdoc,
rustdoc_internals,
rustfmt,
rvalue_static_promotion,
s,
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 @@ -166,7 +166,8 @@
#![feature(derive_default_enum)]
#![feature(doc_cfg)]
#![feature(doc_notable_trait)]
#![feature(doc_primitive)]
#![cfg_attr(bootstrap, feature(doc_primitive))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(exhaustive_patterns)]
#![feature(doc_cfg_hide)]
#![feature(extern_types)]
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@
#![feature(decl_macro)]
#![feature(doc_cfg)]
#![feature(doc_cfg_hide)]
#![feature(doc_keyword)]
#![cfg_attr(bootstrap, feature(doc_primitive))]
#![cfg_attr(bootstrap, feature(doc_keyword))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(doc_masked)]
#![feature(doc_notable_trait)]
#![feature(doc_primitive)]
#![feature(dropck_eyepatch)]
#![feature(duration_checked_float)]
#![feature(duration_constants)]
Expand Down
5 changes: 3 additions & 2 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ This is for Rust compiler internal use only.

Since primitive types are defined in the compiler, there's no place to attach documentation
attributes. The `#[doc(primitive)]` attribute is used by the standard library to provide a way
to generate documentation for primitive types, and requires `#![feature(doc_primitive)]` to enable.
to generate documentation for primitive types, and requires `#![feature(rustdoc_internals)]` to
enable.

## Document keywords

Expand All @@ -149,7 +150,7 @@ Rust keywords are documented in the standard library (look for `match` for examp
To do so, the `#[doc(keyword = "...")]` attribute is used. Example:

```rust
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

/// Some documentation about the keyword.
#[doc(keyword = "keyword")]
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! documentation generated so we can test each different features.

#![crate_name = "test_docs"]
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]
#![feature(doc_cfg)]

use std::convert::AsRef;
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-json/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// edition:2018

#![feature(doc_primitive)]
#![feature(rustdoc_internals)]

#[doc(primitive = "usize")]
mod usize {}
Expand Down
3 changes: 1 addition & 2 deletions src/test/rustdoc-ui/coverage/exotic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// compile-flags:-Z unstable-options --show-coverage
// check-pass

#![feature(doc_keyword)]
#![feature(doc_primitive)]
#![feature(rustdoc_internals)]

//! the features only used in std also have entries in the table, so make sure those get pulled out
//! properly as well
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/invalid-keyword.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

#[doc(keyword = "foo df")] //~ ERROR
mod foo {}
2 changes: 1 addition & 1 deletion src/test/rustdoc/keyword.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![crate_name = "foo"]

#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

// @has foo/index.html '//h2[@id="keywords"]' 'Keywords'
// @has foo/index.html '//a[@href="keyword.match.html"]' 'match'
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/tab_title.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

// tests for the html <title> element

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// compile-flags: -Z unstable-options

#![feature(rustc_private)]
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

#![crate_type = "lib"]

Expand Down
5 changes: 0 additions & 5 deletions src/test/ui/feature-gates/feature-gate-doc_keyword.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/feature-gates/feature-gate-doc_keyword.stderr

This file was deleted.

5 changes: 5 additions & 0 deletions src/test/ui/feature-gates/feature-gate-rustdoc_internals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[doc(keyword = "match")] //~ ERROR: `#[doc(keyword)]` is meant for internal use only
/// wonderful
mod foo {}

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

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
2 changes: 1 addition & 1 deletion src/test/ui/rustdoc/doc_keyword.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_type = "lib"]
#![feature(doc_keyword)]
#![feature(rustdoc_internals)]

#![doc(keyword = "hello")] //~ ERROR

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/rustdoc/renamed-features-rustdoc_internals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![feature(doc_keyword)] //~ ERROR
#![feature(doc_primitive)] //~ ERROR
#![crate_type = "lib"]

pub fn foo() {}
19 changes: 19 additions & 0 deletions src/test/ui/rustdoc/renamed-features-rustdoc_internals.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0557]: feature has been removed
--> $DIR/renamed-features-rustdoc_internals.rs:1:12
|
LL | #![feature(doc_keyword)]
| ^^^^^^^^^^^ feature has been removed
|
= note: merged into `#![feature(rustdoc_internals)]`

error[E0557]: feature has been removed
--> $DIR/renamed-features-rustdoc_internals.rs:2:12
|
LL | #![feature(doc_primitive)]
| ^^^^^^^^^^^^^ feature has been removed
|
= note: merged into `#![feature(rustdoc_internals)]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0557`.

0 comments on commit a6a1d7c

Please sign in to comment.