Skip to content

Commit bb46a20

Browse files
Rollup merge of #145356 - GuillaumeGomez:doctest-escaped, r=fmease
Add another example for escaped `#` character in doctest in rustdoc book Fixes #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.
2 parents 858927c + dc0707a commit bb46a20

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/doc/rustdoc/src/write-documentation/documentation-tests.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ We can document it by escaping the initial `#`:
191191
/// ## bar # baz";
192192
```
193193

194+
Here is an example with a macro rule which matches on tokens starting with `#`:
195+
196+
`````rust,no_run
197+
/// ```
198+
/// macro_rules! ignore { (##tag) => {}; }
199+
/// ignore! {
200+
/// ###tag
201+
/// }
202+
/// ```
203+
# fn f() {}
204+
`````
205+
206+
As you can see, the rule is expecting two `#`, so when calling it, we need to add an extra `#`
207+
because the first one is used as escape.
194208

195209
## Using `?` in doc tests
196210

0 commit comments

Comments
 (0)