Skip to content

Commit baaa85a

Browse files
author
Joshua Nelson
authored
Rollup merge of rust-lang#83865 - camelid:disamb-err-fix, r=jyn514
Don't report disambiguator error if link would have been ignored Fixes rust-lang#83859. This prevents us from warning on links such as `<[email protected]>`. Note that we still warn on links such as `<hello@localhost>` because they have no dots in them. However, the links will still work, even though a warning is reported. r? ```@jyn514```
2 parents 3880665 + 45ccd50 commit baaa85a

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,18 @@ impl LinkCollector<'_, '_> {
945945
Ok(Some((d, path))) => (path.trim(), Some(d)),
946946
Ok(None) => (link.trim(), None),
947947
Err((err_msg, relative_range)) => {
948-
let disambiguator_range = (no_backticks_range.start + relative_range.start)
949-
..(no_backticks_range.start + relative_range.end);
950-
disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
948+
if !should_ignore_link_with_disambiguators(link) {
949+
// Only report error if we would not have ignored this link.
950+
// See issue #83859.
951+
let disambiguator_range = (no_backticks_range.start + relative_range.start)
952+
..(no_backticks_range.start + relative_range.end);
953+
disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
954+
}
951955
return None;
952956
}
953957
};
954958

955-
if path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch))) {
959+
if should_ignore_link(path_str) {
956960
return None;
957961
}
958962

@@ -1482,6 +1486,22 @@ fn range_between_backticks(ori_link: &MarkdownLink) -> Range<usize> {
14821486
..(ori_link.range.start + before_second_backtick_group)
14831487
}
14841488

1489+
/// Returns true if we should ignore `link` due to it being unlikely
1490+
/// that it is an intra-doc link. `link` should still have disambiguators
1491+
/// if there were any.
1492+
///
1493+
/// The difference between this and [`should_ignore_link()`] is that this
1494+
/// check should only be used on links that still have disambiguators.
1495+
fn should_ignore_link_with_disambiguators(link: &str) -> bool {
1496+
link.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;@()".contains(ch)))
1497+
}
1498+
1499+
/// Returns true if we should ignore `path_str` due to it being unlikely
1500+
/// that it is an intra-doc link.
1501+
fn should_ignore_link(path_str: &str) -> bool {
1502+
path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch)))
1503+
}
1504+
14851505
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
14861506
/// Disambiguators for a link.
14871507
crate enum Disambiguator {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![deny(warnings)]
2+
3+
//! Email me at <hello@localhost>.
4+
//~^ ERROR unknown disambiguator `hello`
5+
6+
//! This should *not* warn: <[email protected]>.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unknown disambiguator `hello`
2+
--> $DIR/email-address-localhost.rs:3:18
3+
|
4+
LL | //! Email me at <hello@localhost>.
5+
| ^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/email-address-localhost.rs:1:9
9+
|
10+
LL | #![deny(warnings)]
11+
| ^^^^^^^^
12+
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Email me at <[email protected]>.
2+
//! Email me at <[email protected]>.
3+
//! Email me at <hello@localhost> (this warns but will still become a link).
4+
// @has email_address/index.html '//a[@href="mailto:[email protected]"]' '[email protected]'
5+
// @has email_address/index.html '//a[@href="mailto:[email protected]"]' '[email protected]'
6+
// @has email_address/index.html '//a[@href="mailto:hello@localhost"]' 'hello@localhost'

0 commit comments

Comments
 (0)