about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-08-13 18:43:04 +0200
committerGitHub <noreply@github.com>2025-08-13 18:43:04 +0200
commitbb46a20df47aff847b728177a6432285d30c6922 (patch)
tree3970f719c860185c1d8f1faa1043d2081a9cf8da
parent858927cc9dfa1287745e8dbee6d81f4f3bd8c8c5 (diff)
parentdc0707a4d85f44d2b714d02be0e78cb1f9cc8fbc (diff)
downloadrust-bb46a20df47aff847b728177a6432285d30c6922.tar.gz
rust-bb46a20df47aff847b728177a6432285d30c6922.zip
Rollup merge of #145356 - GuillaumeGomez:doctest-escaped, r=fmease
Add another example for escaped `#` character in doctest in rustdoc book

Fixes rust-lang/rust#118027.

We don't plan to add a way to not escape the first `#`, so at least we add a more complete example in the rustdoc book with a macro making use of that.
-rw-r--r--src/doc/rustdoc/src/write-documentation/documentation-tests.md14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/doc/rustdoc/src/write-documentation/documentation-tests.md b/src/doc/rustdoc/src/write-documentation/documentation-tests.md
index e6b15e0dbd3..4084c1d962a 100644
--- a/src/doc/rustdoc/src/write-documentation/documentation-tests.md
+++ b/src/doc/rustdoc/src/write-documentation/documentation-tests.md
@@ -191,6 +191,20 @@ We can document it by escaping the initial `#`:
 /// ## bar # baz";
 ```
 
+Here is an example with a macro rule which matches on tokens starting with `#`:
+
+`````rust,no_run
+/// ```
+/// macro_rules! ignore { (##tag) => {}; }
+/// ignore! {
+///     ###tag
+/// }
+/// ```
+# fn f() {}
+`````
+
+As you can see, the rule is expecting two `#`, so when calling it, we need to add an extra `#`
+because the first one is used as escape.
 
 ## Using `?` in doc tests