Skip to content

Commit fc53594

Browse files
committed
Feature-gate pointer and reference in intra-doc links
- Only feature gate associated items - Add docs to unstable book
1 parent edeb631 commit fc53594

File tree

10 files changed

+89
-13
lines changed

10 files changed

+89
-13
lines changed

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ declare_features! (
629629
/// Allows references to types with interior mutability within constants
630630
(active, const_refs_to_cell, "1.51.0", Some(80384), None),
631631

632+
/// Allows using `pointer` and `reference` in intra-doc links
633+
(active, intra_doc_pointers, "1.51.0", Some(80896), None),
632634
// -------------------------------------------------------------------------
633635
// feature-group-end: actual feature gates
634636
// -------------------------------------------------------------------------

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ symbols! {
622622
intel,
623623
into_iter,
624624
into_result,
625+
intra_doc_pointers,
625626
intrinsics,
626627
irrefutable_let_patterns,
627628
isa_attribute,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# `intra-doc-pointers`
2+
3+
The tracking issue for this feature is: [#80896]
4+
5+
[#80896]: https://github.com/rust-lang/rust/issues/80896
6+
7+
------------------------
8+
9+
Rustdoc does not currently allow disambiguating between `*const` and `*mut`, and
10+
raw pointers in intra-doc links are unstable until it does.
11+
12+
```rust
13+
#![feature(intra_doc_pointers)]
14+
//! [pointer::add]
15+
```

src/librustdoc/passes/collect_intra_doc_links.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use rustc_session::lint::{
2020
Lint,
2121
};
2222
use rustc_span::hygiene::{MacroKind, SyntaxContext};
23-
use rustc_span::symbol::Ident;
24-
use rustc_span::symbol::Symbol;
23+
use rustc_span::symbol::{sym, Ident, Symbol};
2524
use rustc_span::DUMMY_SP;
2625
use smallvec::{smallvec, SmallVec};
2726

@@ -1195,7 +1194,7 @@ impl LinkCollector<'_, '_> {
11951194
};
11961195

11971196
match res {
1198-
Res::Primitive(_) => {
1197+
Res::Primitive(prim) => {
11991198
if let Some((kind, id)) = self.kind_side_channel.take() {
12001199
// We're actually resolving an associated item of a primitive, so we need to
12011200
// verify the disambiguator (if any) matches the type of the associated item.
@@ -1206,6 +1205,29 @@ impl LinkCollector<'_, '_> {
12061205
// valid omission. See https://github.com/rust-lang/rust/pull/80660#discussion_r551585677
12071206
// for discussion on the matter.
12081207
verify(kind, id)?;
1208+
1209+
if prim == PrimitiveType::RawPointer
1210+
&& !self.cx.tcx.features().intra_doc_pointers
1211+
{
1212+
let span = super::source_span_for_markdown_range(
1213+
cx,
1214+
dox,
1215+
&ori_link.range,
1216+
&item.attrs,
1217+
)
1218+
.unwrap_or_else(|| {
1219+
span_of_attrs(&item.attrs).unwrap_or(item.source.span())
1220+
});
1221+
1222+
rustc_session::parse::feature_err(
1223+
&self.cx.tcx.sess.parse_sess,
1224+
sym::intra_doc_pointers,
1225+
span,
1226+
"linking to associated items of raw pointers is experimental",
1227+
)
1228+
.note("rustdoc does not allow disambiguating between `*const` and `*mut`, and pointers are unstable until it does")
1229+
.emit();
1230+
}
12091231
} else {
12101232
match disambiguator {
12111233
Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => {}
@@ -1215,6 +1237,7 @@ impl LinkCollector<'_, '_> {
12151237
}
12161238
}
12171239
}
1240+
12181241
Some(ItemLink { link: ori_link.link, link_text, did: None, fragment })
12191242
}
12201243
Res::Def(kind, id) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! [pointer::add]
2+
//~^ ERROR: experimental
3+
//! [pointer::wrapping_add]
4+
//~^ ERROR: experimental
5+
//! [pointer] // This is explicitly allowed
6+
//! [reference] // This is explicitly allowed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0658]: linking to associated items of raw pointers is experimental
2+
--> $DIR/feature-gate-intra-doc-pointers.rs:1:6
3+
|
4+
LL | //! [pointer::add]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: see issue #80896 <https://github.com/rust-lang/rust/issues/80896> for more information
8+
= help: add `#![feature(intra_doc_pointers)]` to the crate attributes to enable
9+
= note: rustdoc does not allow disambiguating between `*const` and `*mut`, and pointers are unstable until it does
10+
11+
error[E0658]: linking to associated items of raw pointers is experimental
12+
--> $DIR/feature-gate-intra-doc-pointers.rs:3:6
13+
|
14+
LL | //! [pointer::wrapping_add]
15+
| ^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #80896 <https://github.com/rust-lang/rust/issues/80896> for more information
18+
= help: add `#![feature(intra_doc_pointers)]` to the crate attributes to enable
19+
= note: rustdoc does not allow disambiguating between `*const` and `*mut`, and pointers are unstable until it does
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0658`.

src/test/rustdoc-ui/intra-doc/non-path-primitives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(broken_intra_doc_links)]
2+
#![feature(intra_doc_pointers)]
23
// These are links that could reasonably expected to work, but don't.
34

45
// `[]` isn't supported because it had too many false positives.

src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unresolved link to `T`
2-
--> $DIR/non-path-primitives.rs:11:7
2+
--> $DIR/non-path-primitives.rs:12:7
33
|
44
LL | //! [[T]::rotate_left]
55
| ^ no item named `T` in scope
@@ -12,55 +12,55 @@ LL | #![deny(broken_intra_doc_links)]
1212
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
1313

1414
error: unresolved link to `Z`
15-
--> $DIR/non-path-primitives.rs:13:5
15+
--> $DIR/non-path-primitives.rs:14:5
1616
|
1717
LL | //![Z]([T; N]::map)
1818
| ^ no item named `Z` in scope
1919
|
2020
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2121

2222
error: unresolved link to `Z`
23-
--> $DIR/non-path-primitives.rs:16:6
23+
--> $DIR/non-path-primitives.rs:17:6
2424
|
2525
LL | //! [Z][]
2626
| ^ no item named `Z` in scope
2727
|
2828
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2929

3030
error: unresolved link to `Z`
31-
--> $DIR/non-path-primitives.rs:18:6
31+
--> $DIR/non-path-primitives.rs:19:6
3232
|
3333
LL | //! [Z]: [T; N]::map
3434
| ^ no item named `Z` in scope
3535
|
3636
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3737

3838
error: unresolved link to `unit::eq`
39-
--> $DIR/non-path-primitives.rs:27:6
39+
--> $DIR/non-path-primitives.rs:28:6
4040
|
4141
LL | //! [unit::eq]
4242
| ^^^^^^^^ the builtin type `unit` has no associated item named `eq`
4343

4444
error: unresolved link to `tuple::eq`
45-
--> $DIR/non-path-primitives.rs:28:6
45+
--> $DIR/non-path-primitives.rs:29:6
4646
|
4747
LL | //! [tuple::eq]
4848
| ^^^^^^^^^ the builtin type `tuple` has no associated item named `eq`
4949

5050
error: unresolved link to `fn::eq`
51-
--> $DIR/non-path-primitives.rs:29:6
51+
--> $DIR/non-path-primitives.rs:30:6
5252
|
5353
LL | //! [fn::eq]
5454
| ^^^^^^ the builtin type `fn` has no associated item named `eq`
5555

5656
error: unresolved link to `never::eq`
57-
--> $DIR/non-path-primitives.rs:30:6
57+
--> $DIR/non-path-primitives.rs:31:6
5858
|
5959
LL | //! [never::eq]
6060
| ^^^^^^^^^ the builtin type `never` has no associated item named `eq`
6161

6262
error: unresolved link to `reference::deref`
63-
--> $DIR/non-path-primitives.rs:34:6
63+
--> $DIR/non-path-primitives.rs:35:6
6464
|
6565
LL | //! [reference::deref]
6666
| ^^^^^^^^^^^^^^^^ the builtin type `reference` has no associated item named `deref`

src/test/rustdoc/intra-doc/non-path-primitives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ignore-tidy-linelength
22
#![crate_name = "foo"]
3+
#![feature(intra_doc_pointers)]
34
#![deny(broken_intra_doc_links)]
45

56
// @has foo/index.html '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'slice::rotate_left'

src/tools/tidy/src/features.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ pub fn check(
8585
assert!(!lib_features.is_empty());
8686

8787
super::walk_many(
88-
&[&src_path.join("test/ui"), &src_path.join("test/ui-fulldeps")],
88+
&[
89+
&src_path.join("test/ui"),
90+
&src_path.join("test/ui-fulldeps"),
91+
&src_path.join("test/rustdoc-ui"),
92+
],
8993
&mut |path| super::filter_dirs(path),
9094
&mut |entry, contents| {
9195
let file = entry.path();

0 commit comments

Comments
 (0)