Preserve unicode escapes in format string literals when pretty-printing AST
This commit is contained in:
parent
98c1e3d95b
commit
587899e9ca
@ -684,8 +684,8 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
|
||||
for piece in pieces {
|
||||
match piece {
|
||||
FormatArgsPiece::Literal(s) => {
|
||||
for c in s.as_str().escape_debug() {
|
||||
template.push(c);
|
||||
for c in s.as_str().chars() {
|
||||
template.extend(c.escape_debug());
|
||||
if let '{' | '}' = c {
|
||||
template.push(c);
|
||||
}
|
||||
|
21
tests/pretty/format-args-str-escape.pp
Normal file
21
tests/pretty/format-args-str-escape.pp
Normal file
@ -0,0 +1,21 @@
|
||||
#![feature(prelude_import)]
|
||||
#![no_std]
|
||||
#[prelude_import]
|
||||
use ::std::prelude::rust_2015::*;
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
// pretty-compare-only
|
||||
// pretty-mode:expanded
|
||||
// pp-exact:format-args-str-escape.pp
|
||||
|
||||
fn main() {
|
||||
{ ::std::io::_print(format_args!("\u{1b}[1mHello, world!\u{1b}[0m\n")); };
|
||||
{ ::std::io::_print(format_args!("\u{1b}[1mHello, world!\u{1b}[0m\n")); };
|
||||
{
|
||||
::std::io::_print(format_args!("Not an escape sequence: \\u{{1B}}[1mbold\\x1B[0m\n"));
|
||||
};
|
||||
{
|
||||
::std::io::_print(format_args!("{0}\n",
|
||||
"\x1B[1mHello, world!\x1B[0m"));
|
||||
};
|
||||
}
|
10
tests/pretty/format-args-str-escape.rs
Normal file
10
tests/pretty/format-args-str-escape.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// pretty-compare-only
|
||||
// pretty-mode:expanded
|
||||
// pp-exact:format-args-str-escape.pp
|
||||
|
||||
fn main() {
|
||||
println!("\x1B[1mHello, world!\x1B[0m");
|
||||
println!("\u{1B}[1mHello, world!\u{1B}[0m");
|
||||
println!("Not an escape sequence: \\u{{1B}}[1mbold\\x1B[0m");
|
||||
println!("{}", "\x1B[1mHello, world!\x1B[0m");
|
||||
}
|
Loading…
Reference in New Issue
Block a user