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.
This commit is contained in:
Guillaume Gomez 2025-08-13 18:43:04 +02:00 committed by GitHub
commit bb46a20df4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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