-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #108459 - benediktwerner:rustdoc-fix-link-match, r=Gu…
…illaumeGomez rustdoc: Fix LinkReplacer link matching It currently just uses the first link with the same href which might not necessarily be the matching one. This fixes replacements when there are several links to the same item but with different text (e.g. `[X] and [struct@X]`). It also fixes replacements in summaries since those use a links list with empty hrefs, so currently all links would always match the first link by href but then not match its text. This could also lead to a panic in the `original_lext[1..len() - 1]` part when the first link only has a single character, which is why the new code uses `.get(..)` instead.
- Loading branch information
Showing
3 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#![deny(rustdoc::broken_intra_doc_links)] | ||
|
||
pub struct S; | ||
pub mod char {} | ||
|
||
// Ensure this doesn't ICE due to trying to slice off non-existent backticks from "S" | ||
|
||
/// See [S] and [`S`] | ||
pub struct MyStruct1; | ||
|
||
// Ensure that link texts are replaced correctly even if there are multiple links with | ||
// the same target but different text | ||
|
||
/// See also [crate::char] and [mod@char] and [prim@char] | ||
// @has issue_108459/struct.MyStruct2.html '//*[@href="char/index.html"]' 'crate::char' | ||
// @has - '//*[@href="char/index.html"]' 'char' | ||
// @has - '//*[@href="{{channel}}/std/primitive.char.html"]' 'char' | ||
pub struct MyStruct2; | ||
|
||
/// See also [mod@char] and [prim@char] and [crate::char] | ||
// @has issue_108459/struct.MyStruct3.html '//*[@href="char/index.html"]' 'crate::char' | ||
// @has - '//*[@href="char/index.html"]' 'char' | ||
// @has - '//*[@href="{{channel}}/std/primitive.char.html"]' 'char' | ||
pub struct MyStruct3; | ||
|
||
// Ensure that links are correct even if there are multiple links with the same text but | ||
// different targets | ||
|
||
/// See also [char][mod@char] and [char][prim@char] | ||
// @has issue_108459/struct.MyStruct4.html '//*[@href="char/index.html"]' 'char' | ||
// @has - '//*[@href="{{channel}}/std/primitive.char.html"]' 'char' | ||
pub struct MyStruct4; | ||
|
||
/// See also [char][prim@char] and [char][crate::char] | ||
// @has issue_108459/struct.MyStruct5.html '//*[@href="char/index.html"]' 'char' | ||
// @has - '//*[@href="{{channel}}/std/primitive.char.html"]' 'char' | ||
pub struct MyStruct5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters