Skip to content

Commit a6a1d7c

Browse files
Rollup merge of #90420 - GuillaumeGomez:rustdoc-internals-feature, r=camelid
Create rustdoc_internals feature gate As suggested by ``@camelid`` [here](#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 #90418. What do you think ``@rust-lang/rustdoc`` ?
2 parents cbe563a + 9447d1f commit a6a1d7c

File tree

22 files changed

+72
-37
lines changed

22 files changed

+72
-37
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
325325
cfg_hide => doc_cfg_hide
326326
masked => doc_masked
327327
notable_trait => doc_notable_trait
328-
keyword => doc_keyword
329328
);
329+
330+
if nested_meta.has_name(sym::keyword) {
331+
let msg = "`#[doc(keyword)]` is meant for internal use only";
332+
gate_feature_post!(self, rustdoc_internals, attr.span, msg);
333+
}
330334
}
331335
}
332336

compiler/rustc_feature/src/active.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ declare_features! (
206206
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
207207
/// Allows using compiler's own crates.
208208
(active, rustc_private, "1.0.0", Some(27812), None),
209+
/// Allows using internal rustdoc features like `doc(primitive)` or `doc(keyword)`.
210+
(active, rustdoc_internals, "1.58.0", Some(90418), None),
209211
/// Allows using `#[start]` on a function indicating that it is the program entrypoint.
210212
(active, start, "1.0.0", Some(29633), None),
211213
/// Allows using `#[structural_match]` which indicates that a type is structurally matchable.
@@ -366,12 +368,8 @@ declare_features! (
366368
(active, doc_cfg, "1.21.0", Some(43781), None),
367369
/// Allows `#[doc(cfg_hide(...))]`.
368370
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
369-
/// Allows using `#[doc(keyword = "...")]`.
370-
(active, doc_keyword, "1.28.0", Some(51315), None),
371371
/// Allows `#[doc(masked)]`.
372372
(active, doc_masked, "1.21.0", Some(44027), None),
373-
/// Allows using doc(primitive) without a future-incompat warning
374-
(active, doc_primitive, "1.56.0", Some(88070), None),
375373
/// Allows `X..Y` patterns.
376374
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
377375
/// Allows exhaustive pattern matching on types that contain uninhabited types.

compiler/rustc_feature/src/removed.rs

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ declare_features! (
7676
/// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
7777
(removed, custom_derive, "1.32.0", Some(29644), None,
7878
Some("subsumed by `#[proc_macro_derive]`")),
79+
/// Allows using `#[doc(keyword = "...")]`.
80+
(removed, doc_keyword, "1.28.0", Some(51315), None,
81+
Some("merged into `#![feature(rustdoc_internals)]`")),
82+
/// Allows using `doc(primitive)` without a future-incompat warning.
83+
(removed, doc_primitive, "1.56.0", Some(88070), None,
84+
Some("merged into `#![feature(rustdoc_internals)]`")),
7985
/// Allows `#[doc(spotlight)]`.
8086
/// The attribute was renamed to `#[doc(notable_trait)]`
8187
/// and the feature to `doc_notable_trait`.

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ impl CheckAttrVisitor<'tcx> {
982982
}
983983

984984
sym::primitive => {
985-
if !self.tcx.features().doc_primitive {
985+
if !self.tcx.features().rustdoc_internals {
986986
self.tcx.struct_span_lint_hir(
987987
INVALID_DOC_ATTRIBUTES,
988988
hir_id,

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ symbols! {
11551155
rustc_unsafe_specialization_marker,
11561156
rustc_variance,
11571157
rustdoc,
1158+
rustdoc_internals,
11581159
rustfmt,
11591160
rvalue_static_promotion,
11601161
s,

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@
166166
#![feature(derive_default_enum)]
167167
#![feature(doc_cfg)]
168168
#![feature(doc_notable_trait)]
169-
#![feature(doc_primitive)]
169+
#![cfg_attr(bootstrap, feature(doc_primitive))]
170+
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
170171
#![feature(exhaustive_patterns)]
171172
#![feature(doc_cfg_hide)]
172173
#![feature(extern_types)]

library/std/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@
275275
#![feature(decl_macro)]
276276
#![feature(doc_cfg)]
277277
#![feature(doc_cfg_hide)]
278-
#![feature(doc_keyword)]
278+
#![cfg_attr(bootstrap, feature(doc_primitive))]
279+
#![cfg_attr(bootstrap, feature(doc_keyword))]
280+
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
279281
#![feature(doc_masked)]
280282
#![feature(doc_notable_trait)]
281-
#![feature(doc_primitive)]
282283
#![feature(dropck_eyepatch)]
283284
#![feature(duration_checked_float)]
284285
#![feature(duration_constants)]

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ This is for Rust compiler internal use only.
138138

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

143144
## Document keywords
144145

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

151152
```rust
152-
#![feature(doc_keyword)]
153+
#![feature(rustdoc_internals)]
153154

154155
/// Some documentation about the keyword.
155156
#[doc(keyword = "keyword")]

src/test/rustdoc-gui/src/test_docs/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! documentation generated so we can test each different features.
33
44
#![crate_name = "test_docs"]
5-
#![feature(doc_keyword)]
5+
#![feature(rustdoc_internals)]
66
#![feature(doc_cfg)]
77

88
use std::convert::AsRef;

src/test/rustdoc-json/primitive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition:2018
22

3-
#![feature(doc_primitive)]
3+
#![feature(rustdoc_internals)]
44

55
#[doc(primitive = "usize")]
66
mod usize {}

src/test/rustdoc-ui/coverage/exotic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// compile-flags:-Z unstable-options --show-coverage
22
// check-pass
33

4-
#![feature(doc_keyword)]
5-
#![feature(doc_primitive)]
4+
#![feature(rustdoc_internals)]
65

76
//! the features only used in std also have entries in the table, so make sure those get pulled out
87
//! properly as well
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(doc_keyword)]
1+
#![feature(rustdoc_internals)]
22

33
#[doc(keyword = "foo df")] //~ ERROR
44
mod foo {}

src/test/rustdoc/keyword.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_name = "foo"]
22

3-
#![feature(doc_keyword)]
3+
#![feature(rustdoc_internals)]
44

55
// @has foo/index.html '//h2[@id="keywords"]' 'Keywords'
66
// @has foo/index.html '//a[@href="keyword.match.html"]' 'match'

src/test/rustdoc/tab_title.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
2-
#![feature(doc_keyword)]
2+
#![feature(rustdoc_internals)]
33

44
// tests for the html <title> element
55

src/test/ui-fulldeps/internal-lints/existing_doc_keyword.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// compile-flags: -Z unstable-options
22

33
#![feature(rustc_private)]
4-
#![feature(doc_keyword)]
4+
#![feature(rustdoc_internals)]
55

66
#![crate_type = "lib"]
77

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

-5
This file was deleted.

src/test/ui/feature-gates/feature-gate-doc_keyword.stderr

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[doc(keyword = "match")] //~ ERROR: `#[doc(keyword)]` is meant for internal use only
2+
/// wonderful
3+
mod foo {}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: `#[doc(keyword)]` is meant for internal use only
2+
--> $DIR/feature-gate-rustdoc_internals.rs:1:1
3+
|
4+
LL | #[doc(keyword = "match")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #90418 <https://github.com/rust-lang/rust/issues/90418> for more information
8+
= help: add `#![feature(rustdoc_internals)]` 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/rustdoc/doc_keyword.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_type = "lib"]
2-
#![feature(doc_keyword)]
2+
#![feature(rustdoc_internals)]
33

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(doc_keyword)] //~ ERROR
2+
#![feature(doc_primitive)] //~ ERROR
3+
#![crate_type = "lib"]
4+
5+
pub fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0557]: feature has been removed
2+
--> $DIR/renamed-features-rustdoc_internals.rs:1:12
3+
|
4+
LL | #![feature(doc_keyword)]
5+
| ^^^^^^^^^^^ feature has been removed
6+
|
7+
= note: merged into `#![feature(rustdoc_internals)]`
8+
9+
error[E0557]: feature has been removed
10+
--> $DIR/renamed-features-rustdoc_internals.rs:2:12
11+
|
12+
LL | #![feature(doc_primitive)]
13+
| ^^^^^^^^^^^^^ feature has been removed
14+
|
15+
= note: merged into `#![feature(rustdoc_internals)]`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0557`.

0 commit comments

Comments
 (0)