Skip to content

Commit 3ca197e

Browse files
authored
Rollup merge of #83865 - camelid:disamb-err-fix, r=jyn514
Don't report disambiguator error if link would have been ignored Fixes #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 98e7a4e + 45ccd50 commit 3ca197e

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
@@ -978,14 +978,18 @@ impl LinkCollector<'_, '_> {
978978
Ok(Some((d, path))) => (path.trim(), Some(d)),
979979
Ok(None) => (link.trim(), None),
980980
Err((err_msg, relative_range)) => {
981-
let disambiguator_range = (no_backticks_range.start + relative_range.start)
982-
..(no_backticks_range.start + relative_range.end);
983-
disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
981+
if !should_ignore_link_with_disambiguators(link) {
982+
// Only report error if we would not have ignored this link.
983+
// See issue #83859.
984+
let disambiguator_range = (no_backticks_range.start + relative_range.start)
985+
..(no_backticks_range.start + relative_range.end);
986+
disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
987+
}
984988
return None;
985989
}
986990
};
987991

988-
if path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch))) {
992+
if should_ignore_link(path_str) {
989993
return None;
990994
}
991995

@@ -1515,6 +1519,22 @@ fn range_between_backticks(ori_link: &MarkdownLink) -> Range<usize> {
15151519
..(ori_link.range.start + before_second_backtick_group)
15161520
}
15171521

1522+
/// Returns true if we should ignore `link` due to it being unlikely
1523+
/// that it is an intra-doc link. `link` should still have disambiguators
1524+
/// if there were any.
1525+
///
1526+
/// The difference between this and [`should_ignore_link()`] is that this
1527+
/// check should only be used on links that still have disambiguators.
1528+
fn should_ignore_link_with_disambiguators(link: &str) -> bool {
1529+
link.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;@()".contains(ch)))
1530+
}
1531+
1532+
/// Returns true if we should ignore `path_str` due to it being unlikely
1533+
/// that it is an intra-doc link.
1534+
fn should_ignore_link(path_str: &str) -> bool {
1535+
path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch)))
1536+
}
1537+
15181538
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
15191539
/// Disambiguators for a link.
15201540
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)