Skip to content

Commit b5f265e

Browse files
committed
Auto merge of #66675 - GuillaumeGomez:support-anchors-intra-doc-links, r=kinnison
Support anchors intra doc links Fixes #62833 Part of #43466. cc @ollie27 r? @kinnison
2 parents 809e180 + c1ea1fd commit b5f265e

11 files changed

+328
-106
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+211-78
Large diffs are not rendered by default.

src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[v2]` cannot be resolved, ignoring it...
1+
error: `[v2]` cannot be resolved, ignoring it.
22
--> $DIR/deny-intra-link-resolution-failure.rs:3:6
33
|
44
LL | /// [v2]

src/test/rustdoc-ui/intra-doc-alias-ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it...
1+
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it.
22
--> $DIR/intra-doc-alias-ice.rs:5:30
33
|
44
LL | /// [broken cross-reference](TypeAlias::hoge)

src/test/rustdoc-ui/intra-link-span-ice-55723.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// ## For example:
88
///
99
/// (arr[i])
10-
//~^ ERROR `[i]` cannot be resolved, ignoring it...
10+
//~^ ERROR `[i]` cannot be resolved, ignoring it.
1111
pub fn test_ice() {
1212
unimplemented!();
1313
}

src/test/rustdoc-ui/intra-link-span-ice-55723.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[i]` cannot be resolved, ignoring it...
1+
error: `[i]` cannot be resolved, ignoring it.
22
--> $DIR/intra-link-span-ice-55723.rs:9:10
33
|
44
LL | /// (arr[i])
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![deny(intra_doc_link_resolution_failure)]
2+
3+
// A few tests on anchors.
4+
5+
/// Hello people.
6+
///
7+
/// You can anchors? Here's one!
8+
///
9+
/// # hola
10+
///
11+
/// Isn't it amazing?
12+
pub struct Foo {
13+
pub f: u8,
14+
}
15+
16+
pub enum Enum {
17+
A,
18+
B,
19+
}
20+
21+
/// Have you heard about stuff?
22+
///
23+
/// Like [Foo#hola].
24+
///
25+
/// Or maybe [Foo::f#hola].
26+
//~^ ERROR `[Foo::f#hola]` has an issue with the link anchor.
27+
pub fn foo() {}
28+
29+
/// Empty.
30+
///
31+
/// Another anchor error: [hello#people#!].
32+
//~^ ERROR `[hello#people#!]` has an issue with the link anchor.
33+
pub fn bar() {}
34+
35+
/// Empty?
36+
///
37+
/// Damn enum's variants: [Enum::A#whatever].
38+
//~^ ERROR `[Enum::A#whatever]` has an issue with the link anchor.
39+
pub fn enum_link() {}
40+
41+
/// Primitives?
42+
///
43+
/// [u32#hello]
44+
//~^ ERROR `[u32#hello]` has an issue with the link anchor.
45+
pub fn x() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: `[Foo::f#hola]` has an issue with the link anchor.
2+
--> $DIR/intra-links-anchors.rs:25:15
3+
|
4+
LL | /// Or maybe [Foo::f#hola].
5+
| ^^^^^^^^^^^ struct fields cannot be followed by anchors
6+
|
7+
note: lint level defined here
8+
--> $DIR/intra-links-anchors.rs:1:9
9+
|
10+
LL | #![deny(intra_doc_link_resolution_failure)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: `[hello#people#!]` has an issue with the link anchor.
14+
--> $DIR/intra-links-anchors.rs:31:28
15+
|
16+
LL | /// Another anchor error: [hello#people#!].
17+
| ^^^^^^^^^^^^^^ only one `#` is allowed in a link
18+
19+
error: `[Enum::A#whatever]` has an issue with the link anchor.
20+
--> $DIR/intra-links-anchors.rs:37:28
21+
|
22+
LL | /// Damn enum's variants: [Enum::A#whatever].
23+
| ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors
24+
25+
error: `[u32#hello]` has an issue with the link anchor.
26+
--> $DIR/intra-links-anchors.rs:43:6
27+
|
28+
LL | /// [u32#hello]
29+
| ^^^^^^^^^ primitive types cannot be followed by anchors
30+
31+
error: aborting due to 4 previous errors
32+

src/test/rustdoc-ui/intra-links-warning-crlf.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: `[error]` cannot be resolved, ignoring it...
1+
warning: `[error]` cannot be resolved, ignoring it.
22
--> $DIR/intra-links-warning-crlf.rs:7:6
33
|
44
LL | /// [error]
@@ -7,23 +7,23 @@ LL | /// [error]
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
88
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
99

10-
warning: `[error1]` cannot be resolved, ignoring it...
10+
warning: `[error1]` cannot be resolved, ignoring it.
1111
--> $DIR/intra-links-warning-crlf.rs:12:11
1212
|
1313
LL | /// docs [error1]
1414
| ^^^^^^ cannot be resolved, ignoring
1515
|
1616
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
1717

18-
warning: `[error2]` cannot be resolved, ignoring it...
18+
warning: `[error2]` cannot be resolved, ignoring it.
1919
--> $DIR/intra-links-warning-crlf.rs:15:11
2020
|
2121
LL | /// docs [error2]
2222
| ^^^^^^ cannot be resolved, ignoring
2323
|
2424
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
2525

26-
warning: `[error]` cannot be resolved, ignoring it...
26+
warning: `[error]` cannot be resolved, ignoring it.
2727
--> $DIR/intra-links-warning-crlf.rs:23:20
2828
|
2929
LL | * It also has an [error].

src/test/rustdoc-ui/intra-links-warning.stderr

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: `[Foo::baz]` cannot be resolved, ignoring it...
1+
warning: `[Foo::baz]` cannot be resolved, ignoring it.
22
--> $DIR/intra-links-warning.rs:3:23
33
|
44
LL | //! Test with [Foo::baz], [Bar::foo], ...
@@ -7,71 +7,71 @@ LL | //! Test with [Foo::baz], [Bar::foo], ...
77
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
88
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
99

10-
warning: `[Bar::foo]` cannot be resolved, ignoring it...
10+
warning: `[Bar::foo]` cannot be resolved, ignoring it.
1111
--> $DIR/intra-links-warning.rs:3:35
1212
|
1313
LL | //! Test with [Foo::baz], [Bar::foo], ...
1414
| ^^^^^^^^ cannot be resolved, ignoring
1515
|
1616
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
1717

18-
warning: `[Uniooon::X]` cannot be resolved, ignoring it...
18+
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
1919
--> $DIR/intra-links-warning.rs:6:13
2020
|
2121
LL | //! , [Uniooon::X] and [Qux::Z].
2222
| ^^^^^^^^^^ cannot be resolved, ignoring
2323
|
2424
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
2525

26-
warning: `[Qux::Z]` cannot be resolved, ignoring it...
26+
warning: `[Qux::Z]` cannot be resolved, ignoring it.
2727
--> $DIR/intra-links-warning.rs:6:30
2828
|
2929
LL | //! , [Uniooon::X] and [Qux::Z].
3030
| ^^^^^^ cannot be resolved, ignoring
3131
|
3232
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
3333

34-
warning: `[Uniooon::X]` cannot be resolved, ignoring it...
34+
warning: `[Uniooon::X]` cannot be resolved, ignoring it.
3535
--> $DIR/intra-links-warning.rs:10:14
3636
|
3737
LL | //! , [Uniooon::X] and [Qux::Z].
3838
| ^^^^^^^^^^ cannot be resolved, ignoring
3939
|
4040
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
4141

42-
warning: `[Qux::Z]` cannot be resolved, ignoring it...
42+
warning: `[Qux::Z]` cannot be resolved, ignoring it.
4343
--> $DIR/intra-links-warning.rs:10:31
4444
|
4545
LL | //! , [Uniooon::X] and [Qux::Z].
4646
| ^^^^^^ cannot be resolved, ignoring
4747
|
4848
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
4949

50-
warning: `[Qux:Y]` cannot be resolved, ignoring it...
50+
warning: `[Qux:Y]` cannot be resolved, ignoring it.
5151
--> $DIR/intra-links-warning.rs:14:13
5252
|
5353
LL | /// [Qux:Y]
5454
| ^^^^^ cannot be resolved, ignoring
5555
|
5656
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
5757

58-
warning: `[error]` cannot be resolved, ignoring it...
58+
warning: `[error]` cannot be resolved, ignoring it.
5959
--> $DIR/intra-links-warning.rs:58:30
6060
|
6161
LL | * time to introduce a link [error]*/
6262
| ^^^^^ cannot be resolved, ignoring
6363
|
6464
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
6565

66-
warning: `[error]` cannot be resolved, ignoring it...
66+
warning: `[error]` cannot be resolved, ignoring it.
6767
--> $DIR/intra-links-warning.rs:64:30
6868
|
6969
LL | * time to introduce a link [error]
7070
| ^^^^^ cannot be resolved, ignoring
7171
|
7272
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
7373

74-
warning: `[error]` cannot be resolved, ignoring it...
74+
warning: `[error]` cannot be resolved, ignoring it.
7575
--> $DIR/intra-links-warning.rs:68:1
7676
|
7777
LL | #[doc = "single line [error]"]
@@ -83,7 +83,7 @@ LL | #[doc = "single line [error]"]
8383
^^^^^
8484
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
8585

86-
warning: `[error]` cannot be resolved, ignoring it...
86+
warning: `[error]` cannot be resolved, ignoring it.
8787
--> $DIR/intra-links-warning.rs:71:1
8888
|
8989
LL | #[doc = "single line with \"escaping\" [error]"]
@@ -95,7 +95,7 @@ LL | #[doc = "single line with \"escaping\" [error]"]
9595
^^^^^
9696
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
9797

98-
warning: `[error]` cannot be resolved, ignoring it...
98+
warning: `[error]` cannot be resolved, ignoring it.
9999
--> $DIR/intra-links-warning.rs:74:1
100100
|
101101
LL | / /// Item docs.
@@ -109,47 +109,47 @@ LL | | /// [error]
109109
^^^^^
110110
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
111111

112-
warning: `[error1]` cannot be resolved, ignoring it...
112+
warning: `[error1]` cannot be resolved, ignoring it.
113113
--> $DIR/intra-links-warning.rs:80:11
114114
|
115115
LL | /// docs [error1]
116116
| ^^^^^^ cannot be resolved, ignoring
117117
|
118118
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
119119

120-
warning: `[error2]` cannot be resolved, ignoring it...
120+
warning: `[error2]` cannot be resolved, ignoring it.
121121
--> $DIR/intra-links-warning.rs:82:11
122122
|
123123
LL | /// docs [error2]
124124
| ^^^^^^ cannot be resolved, ignoring
125125
|
126126
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
127127

128-
warning: `[BarA]` cannot be resolved, ignoring it...
128+
warning: `[BarA]` cannot be resolved, ignoring it.
129129
--> $DIR/intra-links-warning.rs:21:10
130130
|
131131
LL | /// bar [BarA] bar
132132
| ^^^^ cannot be resolved, ignoring
133133
|
134134
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
135135

136-
warning: `[BarB]` cannot be resolved, ignoring it...
136+
warning: `[BarB]` cannot be resolved, ignoring it.
137137
--> $DIR/intra-links-warning.rs:27:9
138138
|
139139
LL | * bar [BarB] bar
140140
| ^^^^ cannot be resolved, ignoring
141141
|
142142
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
143143

144-
warning: `[BarC]` cannot be resolved, ignoring it...
144+
warning: `[BarC]` cannot be resolved, ignoring it.
145145
--> $DIR/intra-links-warning.rs:34:6
146146
|
147147
LL | bar [BarC] bar
148148
| ^^^^ cannot be resolved, ignoring
149149
|
150150
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
151151

152-
warning: `[BarD]` cannot be resolved, ignoring it...
152+
warning: `[BarD]` cannot be resolved, ignoring it.
153153
--> $DIR/intra-links-warning.rs:45:1
154154
|
155155
LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
@@ -161,7 +161,7 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
161161
^^^^
162162
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
163163

164-
warning: `[BarF]` cannot be resolved, ignoring it...
164+
warning: `[BarF]` cannot be resolved, ignoring it.
165165
--> $DIR/intra-links-warning.rs:50:9
166166
|
167167
LL | #[doc = $f]

src/test/rustdoc-ui/lint-group.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | #![deny(rustdoc)]
1515
| ^^^^^^^
1616
= note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]`
1717

18-
error: `[error]` cannot be resolved, ignoring it...
18+
error: `[error]` cannot be resolved, ignoring it.
1919
--> $DIR/lint-group.rs:9:29
2020
|
2121
LL | /// what up, let's make an [error]
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// I want...
2+
///
3+
/// # Anchor!
4+
pub struct Something;
5+
6+
// @has intra_links_anchors/struct.SomeOtherType.html
7+
// @has - '//a/@href' '../intra_links_anchors/struct.Something.html#Anchor!'
8+
9+
/// I want...
10+
///
11+
/// To link to [Something#Anchor!]
12+
pub struct SomeOtherType;

0 commit comments

Comments
 (0)