]> git.lizzy.rs Git - rust.git/commit
Merge #8560
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Sun, 18 Apr 2021 02:14:27 +0000 (02:14 +0000)
committerGitHub <noreply@github.com>
Sun, 18 Apr 2021 02:14:27 +0000 (02:14 +0000)
commit2ace128dd4c9c2e5d59d21402da53654acb0c7e4
tree22d190bf73b49859c8fed6bf6d666f737e32ee7b
parent19fc1f333f64e76784ced4ea185e62329d0defb6
parentf92be7eaabe27387a2d860c3842443bf32e99c73
Merge #8560

8560: Escape characters in doc comments in macros correctly r=jonas-schievink a=ChayimFriedman2

Previously they were escaped twice, both by `.escape_default()` and the debug view of strings (`{:?}`). This leads to things like newlines or tabs in documentation comments being `\\n`, but we unescape literals only once, ending up with `\n`.

This was hard to spot because CMark unescaped them (at least for `'` and `"`), but it did not do so in code blocks.

This also was the root cause of #7781. This issue was solved by using `.escape_debug()` instead of `.escape_default()`, but the real issue remained.
We can bring the `.escape_default()` back by now, however I didn't do it because it is probably slower than `.escape_debug()` (more work to do), and also in order to change the code the least.

Example (the keyword and primitive docs are `include!()`d at https://doc.rust-lang.org/src/std/lib.rs.html#570-578, and thus originate from macro):

Before:
![image](https://user-images.githubusercontent.com/24700207/115130096-40544300-9ff5-11eb-847b-969e7034e8a4.png)

After:
![image](https://user-images.githubusercontent.com/24700207/115130143-9cb76280-9ff5-11eb-9281-323746089440.png)

Co-authored-by: Chayim Refael Friedman <chayimfr@gmail.com>
crates/mbe/src/syntax_bridge.rs
crates/mbe/src/tests/expand.rs