Skip to content

Commit 6ac52f0

Browse files
committed
Don't process [] and () in intra-doc links
These caused several false positives when documenting rustc, which means there will likely be many more false positives in the rest of the ecosystem.
1 parent 8842c1c commit 6ac52f0

File tree

4 files changed

+109
-32
lines changed

4 files changed

+109
-32
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl LinkCollector<'_, '_> {
10201020
(link.trim(), None)
10211021
};
10221022

1023-
if path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*()[]&;".contains(ch))) {
1023+
if path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch))) {
10241024
return None;
10251025
}
10261026

@@ -2085,10 +2085,11 @@ fn resolve_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
20852085
"char" => Char,
20862086
"bool" | "true" | "false" => Bool,
20872087
"str" => Str,
2088-
"slice" | "&[]" | "[T]" => Slice,
2089-
"array" | "[]" | "[T;N]" => Array,
2090-
"tuple" | "(,)" => Tuple,
2091-
"unit" | "()" => Unit,
2088+
// See #80181 for why these don't have symbols associated.
2089+
"slice" => Slice,
2090+
"array" => Array,
2091+
"tuple" => Tuple,
2092+
"unit" => Unit,
20922093
"pointer" | "*" | "*const" | "*mut" => RawPointer,
20932094
"reference" | "&" | "&mut" => Reference,
20942095
"fn" => Fn,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![deny(broken_intra_doc_links)]
2+
// These are links that could reasonably expected to work, but don't.
3+
4+
// `[]` isn't supported because it had too many false positives.
5+
//! [X]([T]::not_here)
6+
//! [Y](&[]::not_here)
7+
//! [X]([]::not_here)
8+
//! [Y]([T;N]::not_here)
9+
10+
// These don't work because markdown syntax doesn't allow it.
11+
//! [[T]::rotate_left] //~ ERROR unresolved link to `T`
12+
//! [&[]::not_here]
13+
//![Z]([T; N]::map) //~ ERROR unresolved link to `Z`
14+
//! [`[T; N]::map`]
15+
//! [[]::map]
16+
//! [Z][] //~ ERROR unresolved link to `Z`
17+
//!
18+
//! [Z]: [T; N]::map //~ ERROR unresolved link to `Z`
19+
20+
// `()` isn't supported because it had too many false positives.
21+
//! [()::not_here]
22+
//! [X]((,)::not_here)
23+
//! [(,)::not_here]
24+
25+
// FIXME: Associated items on some primitives aren't working, because the impls
26+
// are part of the compiler instead of being part of the source code.
27+
//! [unit::eq] //~ ERROR unresolved
28+
//! [tuple::eq] //~ ERROR unresolved
29+
//! [fn::eq] //~ ERROR unresolved
30+
//! [never::eq] //~ ERROR unresolved
31+
32+
// FIXME(#78800): This breaks because it's a blanket impl
33+
// (I think? Might break for other reasons too.)
34+
//! [reference::deref] //~ ERROR unresolved
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
error: unresolved link to `T`
2+
--> $DIR/non-path-primitives.rs:11:7
3+
|
4+
LL | //! [[T]::rotate_left]
5+
| ^ no item named `T` in scope
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/non-path-primitives.rs:1:9
9+
|
10+
LL | #![deny(broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
13+
14+
error: unresolved link to `Z`
15+
--> $DIR/non-path-primitives.rs:13:5
16+
|
17+
LL | //![Z]([T; N]::map)
18+
| ^ no item named `Z` in scope
19+
|
20+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
21+
22+
error: unresolved link to `Z`
23+
--> $DIR/non-path-primitives.rs:16:6
24+
|
25+
LL | //! [Z][]
26+
| ^ no item named `Z` in scope
27+
|
28+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
29+
30+
error: unresolved link to `Z`
31+
--> $DIR/non-path-primitives.rs:18:6
32+
|
33+
LL | //! [Z]: [T; N]::map
34+
| ^ no item named `Z` in scope
35+
|
36+
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
37+
38+
error: unresolved link to `unit::eq`
39+
--> $DIR/non-path-primitives.rs:27:6
40+
|
41+
LL | //! [unit::eq]
42+
| ^^^^^^^^ the builtin type `unit` has no associated item named `eq`
43+
44+
error: unresolved link to `tuple::eq`
45+
--> $DIR/non-path-primitives.rs:28:6
46+
|
47+
LL | //! [tuple::eq]
48+
| ^^^^^^^^^ the builtin type `tuple` has no associated item named `eq`
49+
50+
error: unresolved link to `fn::eq`
51+
--> $DIR/non-path-primitives.rs:29:6
52+
|
53+
LL | //! [fn::eq]
54+
| ^^^^^^ the builtin type `fn` has no associated item named `eq`
55+
56+
error: unresolved link to `never::eq`
57+
--> $DIR/non-path-primitives.rs:30:6
58+
|
59+
LL | //! [never::eq]
60+
| ^^^^^^^^^ the builtin type `never` has no associated item named `eq`
61+
62+
error: unresolved link to `reference::deref`
63+
--> $DIR/non-path-primitives.rs:34:6
64+
|
65+
LL | //! [reference::deref]
66+
| ^^^^^^^^^^^^^^^^ the builtin type `reference` has no associated item named `deref`
67+
68+
error: aborting due to 9 previous errors
69+

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

-27
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,10 @@
33
#![deny(broken_intra_doc_links)]
44

55
// @has foo/index.html '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'slice::rotate_left'
6-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'X'
7-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'Y'
86
//! [slice::rotate_left]
9-
//! [X]([T]::rotate_left)
10-
//! [Y](&[]::rotate_left)
11-
// These don't work because markdown syntax doesn't allow it.
12-
// [[T]::rotate_left]
13-
//! [&[]::rotate_left]
147
158
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.array.html#method.map"]' 'array::map'
16-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.array.html#method.map"]' 'X'
17-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.array.html#method.map"]' 'Y'
189
//! [array::map]
19-
//! [X]([]::map)
20-
//! [Y]([T;N]::map)
21-
// These don't work because markdown syntax doesn't allow it.
22-
// [Z]([T; N]::map)
23-
//! [`[T; N]::map`]
24-
//! [[]::map]
25-
// [Z][]
26-
//
27-
// [Z]: [T; N]::map
2810
2911
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' 'pointer::is_null'
3012
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*const::is_null'
@@ -35,20 +17,11 @@
3517
//! [*mut::is_null]
3618
//! [*::is_null]
3719
38-
// FIXME: Associated items on some primitives aren't working, because the impls
39-
// are part of the compiler instead of being part of the source code.
40-
4120
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.unit.html"]' 'unit'
42-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.unit.html"]' '()'
4321
//! [unit]
44-
//! [()]
4522
4623
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html"]' 'tuple'
47-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html"]' 'X'
48-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html"]' '(,)'
4924
//! [tuple]
50-
//! [X]((,))
51-
//! [(,)]
5225
5326
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.reference.html"]' 'reference'
5427
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.reference.html"]' '&'

0 commit comments

Comments
 (0)