Use Mode
less.
It's passed to numerous places where we just need an `is_byte` bool. Passing the bool avoids the need for some assertions. Also rename `is_bytes()` as `is_byte()`, to better match `Mode::Byte`, `Mode::ByteStr`, and `Mode::RawByteStr`.
This commit is contained in:
parent
84ca2c3bab
commit
34b32b0dac
2 changed files with 29 additions and 31 deletions
|
@ -108,7 +108,7 @@ pub(crate) fn emit_unescape_error(
|
|||
}
|
||||
|
||||
if !has_help {
|
||||
let (prefix, msg) = if mode.is_bytes() {
|
||||
let (prefix, msg) = if mode.is_byte() {
|
||||
("b", "if you meant to write a byte string literal, use double quotes")
|
||||
} else {
|
||||
("", "if you meant to write a `str` literal, use double quotes")
|
||||
|
@ -142,7 +142,7 @@ pub(crate) fn emit_unescape_error(
|
|||
EscapeError::EscapeOnlyChar => {
|
||||
let (c, char_span) = last_char();
|
||||
|
||||
let msg = if mode.is_bytes() {
|
||||
let msg = if mode.is_byte() {
|
||||
"byte constant must be escaped"
|
||||
} else {
|
||||
"character constant must be escaped"
|
||||
|
@ -182,11 +182,11 @@ pub(crate) fn emit_unescape_error(
|
|||
let (c, span) = last_char();
|
||||
|
||||
let label =
|
||||
if mode.is_bytes() { "unknown byte escape" } else { "unknown character escape" };
|
||||
if mode.is_byte() { "unknown byte escape" } else { "unknown character escape" };
|
||||
let ec = escaped_char(c);
|
||||
let mut diag = handler.struct_span_err(span, &format!("{}: `{}`", label, ec));
|
||||
diag.span_label(span, label);
|
||||
if c == '{' || c == '}' && !mode.is_bytes() {
|
||||
if c == '{' || c == '}' && !mode.is_byte() {
|
||||
diag.help(
|
||||
"if used in a formatting string, curly braces are escaped with `{{` and `}}`",
|
||||
);
|
||||
|
@ -196,7 +196,7 @@ pub(crate) fn emit_unescape_error(
|
|||
version control settings",
|
||||
);
|
||||
} else {
|
||||
if !mode.is_bytes() {
|
||||
if !mode.is_byte() {
|
||||
diag.span_suggestion(
|
||||
span_with_quotes,
|
||||
"if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal",
|
||||
|
@ -231,7 +231,7 @@ pub(crate) fn emit_unescape_error(
|
|||
.emit();
|
||||
}
|
||||
EscapeError::NonAsciiCharInByte => {
|
||||
assert!(mode.is_bytes());
|
||||
assert!(mode.is_byte());
|
||||
let (c, span) = last_char();
|
||||
let mut err = handler.struct_span_err(span, "non-ASCII character in byte constant");
|
||||
let postfix = if unicode_width::UnicodeWidthChar::width(c).unwrap_or(1) == 0 {
|
||||
|
@ -271,7 +271,7 @@ pub(crate) fn emit_unescape_error(
|
|||
err.emit();
|
||||
}
|
||||
EscapeError::NonAsciiCharInByteString => {
|
||||
assert!(mode.is_bytes());
|
||||
assert!(mode.is_byte());
|
||||
let (c, span) = last_char();
|
||||
let postfix = if unicode_width::UnicodeWidthChar::width(c).unwrap_or(1) == 0 {
|
||||
format!(" but is {:?}", c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue