Skip to content

Commit c6f5495

Browse files
committed
Auto merge of #115070 - notriddle:notriddle/utf8-redundant-explicit-links, r=GuillaumeGomez,ChAoSUnItY
rustdoc: use unicode-aware checks for redundant explicit link fastpath Fixes #115064 Fixes #115062 Fixes #115116
2 parents c469197 + 3df9b4d commit c6f5495

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1430,20 +1430,15 @@ impl LinkCollector<'_, '_> {
14301430
// Otherwise, check if 2 links are same, if so, skip the resolve process.
14311431
//
14321432
// Notice that this algorithm is passive, might possibly miss actual redudant cases.
1433-
let explicit_link = &explicit_link.to_string();
1433+
let explicit_link = explicit_link.to_string();
14341434
let display_text = ori_link.display_text.as_ref().unwrap();
1435-
let display_len = display_text.len();
1436-
let explicit_len = explicit_link.len();
14371435

1438-
if display_len == explicit_len {
1436+
if display_text.len() == explicit_link.len() {
14391437
// Whether they are same or not, skip the resolve process.
14401438
return;
14411439
}
14421440

1443-
if (explicit_len >= display_len
1444-
&& &explicit_link[(explicit_len - display_len)..] == display_text)
1445-
|| (display_len >= explicit_len
1446-
&& &display_text[(display_len - explicit_len)..] == explicit_link)
1441+
if explicit_link.ends_with(&display_text[..]) || display_text.ends_with(&explicit_link[..])
14471442
{
14481443
self.resolve_with_disambiguator_cached(
14491444
display_res_info,

src/librustdoc/passes/lint/redundant_explicit_links.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,8 @@ fn check_redundant_explicit_link<'md>(
9898

9999
let explicit_link = dest.to_string();
100100
let display_link = link_data.resolvable_link.clone()?;
101-
let explicit_len = explicit_link.len();
102-
let display_len = display_link.len();
103101

104-
if (explicit_len >= display_len
105-
&& &explicit_link[(explicit_len - display_len)..] == display_link)
106-
|| (display_len >= explicit_len
107-
&& &display_link[(display_len - explicit_len)..] == explicit_link)
102+
if explicit_link.ends_with(&display_link) || display_link.ends_with(&explicit_link)
108103
{
109104
match link_type {
110105
LinkType::Inline | LinkType::ReferenceUnknown => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
3+
/// [`…foo`] [`…bar`] [`Err`]
4+
pub struct Broken {}
5+
6+
/// [`…`] [`…`] [`Err`]
7+
pub struct Broken2 {}
8+
9+
/// [`…`][…] [`…`][…] [`Err`]
10+
pub struct Broken3 {}
11+
12+
/// […………………………][Broken3]
13+
pub struct Broken4 {}
14+
15+
/// [Broken3][…………………………]
16+
pub struct Broken5 {}
17+
18+
pub struct Err;

0 commit comments

Comments
 (0)