From 285e574b8ebb10ec329210dbcb1782433555d420 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 24 Sep 2023 20:05:27 +0000 Subject: [PATCH] Fix `.to_string()` of `proc_macro::Literal` (properly print cstr literals) --- library/proc_macro/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index d382fec9352..f08a345db89 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -1411,7 +1411,15 @@ impl Literal { let hashes = get_hashes_str(n); f(&["br", hashes, "\"", symbol, "\"", hashes, suffix]) } - _ => f(&[symbol, suffix]), + bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), + bridge::LitKind::CStrRaw(n) => { + let hashes = get_hashes_str(n); + f(&["cr", hashes, "\"", symbol, "\"", hashes, suffix]) + } + + bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::Err => { + f(&[symbol, suffix]) + } }) } }