about summary refs log tree commit diff
path: root/tests/rustdoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-08-24 19:46:17 +0000
committerbors <bors@rust-lang.org>2025-08-24 19:46:17 +0000
commit809200ec956983fce4ae178b87dada69f01d0820 (patch)
treeff7af177ca1d408d078cc571cb54249ce3a67025 /tests/rustdoc
parent3776358beb5747d938bdefaf47a1c76723e6a372 (diff)
parentd0913c571cde92c4d0db6b1bac94ac320c0e9d2e (diff)
downloadrust-809200ec956983fce4ae178b87dada69f01d0820.tar.gz
rust-809200ec956983fce4ae178b87dada69f01d0820.zip
Auto merge of #137229 - GuillaumeGomez:expand-macro, r=lolbinarycat
Add support for macro expansion in rustdoc source code pages

This is what it looks like:

![Screenshot From 2025-02-18 18-08-51](https://github.com/user-attachments/assets/ce2b3806-6218-47df-94bf-e9e9ed40cd41)

![image](https://github.com/user-attachments/assets/891042db-8632-4dba-9343-e28570c058fe)

You can test it [here](https://rustdoc.crud.net/imperio/macro-expansion/src/lib/lib.rs.html). In this case, I also enabled the `--generate-link-to-definition` to show that both options work well together.

Note: <del>There is a bug currently in firefox where the line numbers are not displayed correctly if they're inside the "macro expansion" span: https://bugzilla.mozilla.org/show_bug.cgi?id=1949948<del> Found a workaround around this bug.

r? `@notriddle`
Diffstat (limited to 'tests/rustdoc')
-rw-r--r--tests/rustdoc/macro/macro_expansion.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/rustdoc/macro/macro_expansion.rs b/tests/rustdoc/macro/macro_expansion.rs
new file mode 100644
index 00000000000..c989ccad967
--- /dev/null
+++ b/tests/rustdoc/macro/macro_expansion.rs
@@ -0,0 +1,28 @@
+// This test checks that patterns and statements are also getting expanded.
+
+//@ compile-flags: -Zunstable-options --generate-macro-expansion
+
+#![crate_name = "foo"]
+
+//@ has 'src/foo/macro_expansion.rs.html'
+//@ count - '//span[@class="expansion"]' 2
+
+macro_rules! pat {
+    ($x:literal) => {
+        Some($x)
+    }
+}
+
+macro_rules! stmt {
+    ($x:expr) => {{
+        let _ = $x;
+    }}
+}
+
+fn bar() {
+    match Some("hello") {
+        pat!("blolb") => {}
+        _ => {}
+    }
+    stmt!(1)
+}