Skip to content

Commit 5bdf9be

Browse files
committed
Raw string to avoid escaped backslashes where possible
1 parent bcac1fd commit 5bdf9be

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/fallback.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,9 @@ impl Literal {
10191019
.starts_with(|next| '0' <= next && next <= '7')
10201020
{
10211021
// circumvent clippy::octal_escapes lint
1022-
"\\x00"
1022+
r"\x00"
10231023
} else {
1024-
"\\0"
1024+
r"\0"
10251025
},
10261026
);
10271027
} else if ch == '\'' {
@@ -1063,10 +1063,10 @@ impl Literal {
10631063
b'\n' => repr.push_str(r"\n"),
10641064
b'\r' => repr.push_str(r"\r"),
10651065
b'"' => repr.push_str("\\\""),
1066-
b'\\' => repr.push_str("\\\\"),
1066+
b'\\' => repr.push_str(r"\\"),
10671067
b'\x20'..=b'\x7E' => repr.push(b as char),
10681068
_ => {
1069-
let _ = write!(repr, "\\x{:02X}", b);
1069+
let _ = write!(repr, r"\x{:02X}", b);
10701070
}
10711071
}
10721072
}

tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn literal_c_string() {
189189
#[test]
190190
fn literal_character() {
191191
assert_eq!(Literal::character('x').to_string(), "'x'");
192-
assert_eq!(Literal::character('\'').to_string(), "'\\''");
192+
assert_eq!(Literal::character('\'').to_string(), r"'\''");
193193
assert_eq!(Literal::character('"').to_string(), "'\"'");
194194
}
195195

@@ -378,7 +378,7 @@ fn roundtrip() {
378378
roundtrip("'a");
379379
roundtrip("'_");
380380
roundtrip("'static");
381-
roundtrip("'\\u{10__FFFF}'");
381+
roundtrip(r"'\u{10__FFFF}'");
382382
roundtrip("\"\\u{10_F0FF__}foo\\u{1_0_0_0__}\"");
383383
}
384384

0 commit comments

Comments
 (0)