Skip to content

Commit 63c765a

Browse files
committed
Auto merge of rust-lang#116124 - WaffleLapkin:fix-proc-macro-literal-to-string, r=compiler-errors
Properly print cstr literals in `proc_macro::Literal::to_string` Previously we printed the contents of the string, rather than the actual string literal (e.g. `the c string` instead of `c"the c string"`). Fixes rust-lang#112820 cc rust-lang#105723
2 parents 18e3116 + 0b03697 commit 63c765a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

proc_macro/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,15 @@ impl Literal {
14181418
let hashes = get_hashes_str(n);
14191419
f(&["br", hashes, "\"", symbol, "\"", hashes, suffix])
14201420
}
1421-
_ => f(&[symbol, suffix]),
1421+
bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]),
1422+
bridge::LitKind::CStrRaw(n) => {
1423+
let hashes = get_hashes_str(n);
1424+
f(&["cr", hashes, "\"", symbol, "\"", hashes, suffix])
1425+
}
1426+
1427+
bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::Err => {
1428+
f(&[symbol, suffix])
1429+
}
14221430
})
14231431
}
14241432
}

0 commit comments

Comments
 (0)