]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #95343 - dtolnay:literals, r=petrochenkov
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Mon, 4 Apr 2022 18:41:30 +0000 (20:41 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Apr 2022 18:41:30 +0000 (20:41 +0200)
commit2d1496a8f62afb3ff3b7e4233c2eb65593d89780
treebf97266ddece38bd6f7f9f1778664c1e9407e6bd
parent98168925f6570a8d0292abd493cf20bde89c7663
parentf383134acc48c97bbf2389aa62d51b9a51535482
Rollup merge of #95343 - dtolnay:literals, r=petrochenkov

Reduce unnecessary escaping in proc_macro::Literal::character/string

I noticed that https://doc.rust-lang.org/proc_macro/struct.Literal.html#method.character is producing unreadable literals that make macro-expanded code unnecessarily hard to read. Since the proc macro server was using `escape_unicode()`, every char is escaped using `\u{…}` regardless of whether there is any need to do so. For example `Literal::character('=')` would previously produce `'\u{3d}'` which unnecessarily obscures the meaning when reading the macro-expanded code.

I've changed Literal::string also in this PR because `str`'s `Debug` impl is also smarter than just calling `escape_debug` on every char. For example `Literal::string("ferris's")` would previously produce `"ferris\'s"` but will now produce `"ferris's"`.
compiler/rustc_expand/src/proc_macro_server.rs