Skip to content

Commit

Permalink
Consistently use repr for the escaped text of a literal
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 14, 2024
1 parent 28e905f commit bcac1fd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/fallback.rs
Expand Up @@ -1049,29 +1049,29 @@ impl Literal {
}

pub fn byte_string(bytes: &[u8]) -> Literal {
let mut escaped = "b\"".to_string();
let mut repr = "b\"".to_string();
let mut bytes = bytes.iter();
while let Some(&b) = bytes.next() {
#[allow(clippy::match_overlapping_arm)]
match b {
b'\0' => escaped.push_str(match bytes.as_slice().first() {
b'\0' => repr.push_str(match bytes.as_slice().first() {
// circumvent clippy::octal_escapes lint
Some(b'0'..=b'7') => r"\x00",
_ => r"\0",
}),
b'\t' => escaped.push_str(r"\t"),
b'\n' => escaped.push_str(r"\n"),
b'\r' => escaped.push_str(r"\r"),
b'"' => escaped.push_str("\\\""),
b'\\' => escaped.push_str("\\\\"),
b'\x20'..=b'\x7E' => escaped.push(b as char),
b'\t' => repr.push_str(r"\t"),
b'\n' => repr.push_str(r"\n"),
b'\r' => repr.push_str(r"\r"),
b'"' => repr.push_str("\\\""),
b'\\' => repr.push_str("\\\\"),
b'\x20'..=b'\x7E' => repr.push(b as char),
_ => {
let _ = write!(escaped, "\\x{:02X}", b);
let _ = write!(repr, "\\x{:02X}", b);
}
}
}
escaped.push('"');
Literal::_new(escaped)
repr.push('"');
Literal::_new(repr)
}

pub fn span(&self) -> Span {
Expand Down

0 comments on commit bcac1fd

Please sign in to comment.