diff --git a/compiler/rustc_lexer/src/unescape.rs b/compiler/rustc_lexer/src/unescape.rs index 6550eed3958..b970c9e4911 100644 --- a/compiler/rustc_lexer/src/unescape.rs +++ b/compiler/rustc_lexer/src/unescape.rs @@ -319,17 +319,17 @@ where where F: FnMut(Range, Result), { - let str = chars.as_str(); - let first_non_space = str + let tail = chars.as_str(); + let first_non_space = tail .bytes() .position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r') - .unwrap_or(str.len()); - if str[1..first_non_space].contains('\n') { + .unwrap_or(tail.len()); + if tail[1..first_non_space].contains('\n') { // The +1 accounts for the escaping slash. let end = start + first_non_space + 1; callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning)); } - let tail = &str[first_non_space..]; + let tail = &tail[first_non_space..]; if let Some(c) = tail.chars().nth(0) { // For error reporting, we would like the span to contain the character that was not // skipped. The +1 is necessary to account for the leading \ that started the escape.