Skip to content

Commit e07045a

Browse files
committed
Simplify Literal::c_string implementation
1 parent 04123c2 commit e07045a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

library/proc_macro/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1355,10 +1355,8 @@ impl Literal {
13551355
/// C string literal.
13561356
#[unstable(feature = "proc_macro_c_str_literals", issue = "119750")]
13571357
pub fn c_string(string: &CStr) -> Literal {
1358-
let quoted = format!("{:?}", string);
1359-
assert!(quoted.starts_with('"') && quoted.ends_with('"'));
1360-
let symbol = &quoted[1..quoted.len() - 1];
1361-
Literal::new(bridge::LitKind::CStr, symbol, None)
1358+
let string = string.to_bytes().escape_ascii().to_string();
1359+
Literal::new(bridge::LitKind::CStr, &string, None)
13621360
}
13631361

13641362
/// Returns the span encompassing this literal.

0 commit comments

Comments
 (0)