about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-08-05 21:21:24 +0000
committerGitHub <noreply@github.com>2025-08-05 21:21:24 +0000
commitae6a56bea2efafe52ecc8d4c18703608a8835015 (patch)
tree0ae0fa6bc154995fd4d7c338724c2b34893140d5
parent4d8547a3317fb5f4804672a25a8c376172f5e38c (diff)
parent6a20b6d0221e4a311d61ad4f39827d6c30dca48f (diff)
downloadrust-ae6a56bea2efafe52ecc8d4c18703608a8835015.tar.gz
rust-ae6a56bea2efafe52ecc8d4c18703608a8835015.zip
Merge pull request #20384 from vxpm/fix-external-docs
fix external docs for exported macros
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/doc_links.rs3
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs24
2 files changed, 26 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
index a5d9a10d2e5..d47cc650793 100644
--- a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
@@ -390,7 +390,8 @@ fn get_doc_links(
 
     let (mut web_url, mut local_url) = get_doc_base_urls(db, target, target_dir, sysroot);
 
-    if let Some(path) = mod_path_of_def(db, target) {
+    let append_mod = !matches!(def, Definition::Macro(m) if m.is_macro_export(db));
+    if append_mod && let Some(path) = mod_path_of_def(db, target) {
         web_url = join_url(web_url, &path);
         local_url = join_url(local_url, &path);
     }
diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs
index 6af156fa668..c2f08f8ca2e 100644
--- a/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/doc_links/tests.rs
@@ -415,6 +415,30 @@ fn foo() {
 }
 
 #[test]
+fn external_docs_macro_export() {
+    check_external_docs(
+        r#"
+//- /lib.rs crate:foo
+pub mod inner {
+    #[macro_export]
+    macro_rules! my_macro {
+        () => {};
+    }
+}
+
+//- /main.rs crate:bar deps:foo
+fn main() {
+    foo::my_m$0acro!();
+}
+        "#,
+        Some("/home/user/project"),
+        Some(expect![[r#"https://docs.rs/foo/*/foo/macro.my_macro.html"#]]),
+        Some(expect![[r#"file:///home/user/project/doc/foo/macro.my_macro.html"#]]),
+        Some("/sysroot"),
+    );
+}
+
+#[test]
 fn doc_links_items_simple() {
     check_doc_links(
         r#"