Skip to content

Commit 2750e36

Browse files
committed
rustdoc: Resolve &str as str
People almost always are referring to `&str`, not `str`, so this will save a manual link resolve in many cases. Note that we already accept `&` (resolves to `reference`) in intra-doc links, so this shouldn't cause breakage.
1 parent f30733a commit 2750e36

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ fn resolve_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
20862086
"f64" => F64,
20872087
"char" => Char,
20882088
"bool" | "true" | "false" => Bool,
2089-
"str" => Str,
2089+
"str" | "&str" => Str,
20902090
// See #80181 for why these don't have symbols associated.
20912091
"slice" => Slice,
20922092
"array" => Array,

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

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.array.html#method.map"]' 'array::map'
99
//! [array::map]
1010
11+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html"]' 'owned str'
12+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html"]' 'str ref'
13+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html#method.is_empty"]' 'str::is_empty'
14+
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html#method.len"]' '&str::len'
15+
//! [owned str][str]
16+
//! [str ref][&str]
17+
//! [str::is_empty]
18+
//! [&str::len]
19+
1120
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' 'pointer::is_null'
1221
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*const::is_null'
1322
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*mut::is_null'

0 commit comments

Comments
 (0)