about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-04-05 13:03:44 +0200
committerGitHub <noreply@github.com>2021-04-05 13:03:44 +0200
commit3ca197e89c9affc76e79f0421e1bb9d65a8ec855 (patch)
treee930e86d52114de16148de08b917c974cb874669 /src/librustdoc
parent98e7a4e7844f5099ec7e15228a42440931072e53 (diff)
parent45ccd50d0e52e006fdd81f854b4cd711ac439e85 (diff)
downloadrust-3ca197e89c9affc76e79f0421e1bb9d65a8ec855.tar.gz
rust-3ca197e89c9affc76e79f0421e1bb9d65a8ec855.zip
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 `<hello@example.com>`.
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````
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 437f42b26dd..545fbf26181 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -978,14 +978,18 @@ impl LinkCollector<'_, '_> {
             Ok(Some((d, path))) => (path.trim(), Some(d)),
             Ok(None) => (link.trim(), None),
             Err((err_msg, relative_range)) => {
-                let disambiguator_range = (no_backticks_range.start + relative_range.start)
-                    ..(no_backticks_range.start + relative_range.end);
-                disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
+                if !should_ignore_link_with_disambiguators(link) {
+                    // Only report error if we would not have ignored this link.
+                    // See issue #83859.
+                    let disambiguator_range = (no_backticks_range.start + relative_range.start)
+                        ..(no_backticks_range.start + relative_range.end);
+                    disambiguator_error(self.cx, &item, dox, disambiguator_range, &err_msg);
+                }
                 return None;
             }
         };
 
-        if path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch))) {
+        if should_ignore_link(path_str) {
             return None;
         }
 
@@ -1515,6 +1519,22 @@ fn range_between_backticks(ori_link: &MarkdownLink) -> Range<usize> {
         ..(ori_link.range.start + before_second_backtick_group)
 }
 
+/// Returns true if we should ignore `link` due to it being unlikely
+/// that it is an intra-doc link. `link` should still have disambiguators
+/// if there were any.
+///
+/// The difference between this and [`should_ignore_link()`] is that this
+/// check should only be used on links that still have disambiguators.
+fn should_ignore_link_with_disambiguators(link: &str) -> bool {
+    link.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;@()".contains(ch)))
+}
+
+/// Returns true if we should ignore `path_str` due to it being unlikely
+/// that it is an intra-doc link.
+fn should_ignore_link(path_str: &str) -> bool {
+    path_str.contains(|ch: char| !(ch.is_alphanumeric() || ":_<>, !*&;".contains(ch)))
+}
+
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
 /// Disambiguators for a link.
 crate enum Disambiguator {