Skip to content

Commit

Permalink
Inline printable function
Browse files Browse the repository at this point in the history
  • Loading branch information
5225225 committed Nov 16, 2021
1 parent 17b5e2d commit 09e59c2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Expand Up @@ -7,10 +7,6 @@ use rustc_errors::{pluralize, Applicability, Handler};
use rustc_lexer::unescape::{EscapeError, Mode};
use rustc_span::{BytePos, Span};

fn printing(ch: char) -> bool {
unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0) != 0 && !ch.is_whitespace()
}

pub(crate) fn emit_unescape_error(
handler: &Handler,
// interior part of the literal, without quotes
Expand Down Expand Up @@ -87,7 +83,13 @@ pub(crate) fn emit_unescape_error(
);
}
} else {
let printable: Vec<char> = lit.chars().filter(|x| printing(*x)).collect();
let printable: Vec<char> = lit
.chars()
.filter(|&x| {
unicode_width::UnicodeWidthChar::width(x).unwrap_or(0) != 0
&& !x.is_whitespace()
})
.collect();

if let [ch] = printable.as_slice() {
has_help = true;
Expand Down

0 comments on commit 09e59c2

Please sign in to comment.