From d6f722d79cf01f8305288235d82e13a6863711f5 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sun, 3 Nov 2019 12:55:05 +0300 Subject: [PATCH] librustc_lexer: Simplify "double_quoted_string" method --- src/librustc_lexer/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index 2edf3bd78ef..6653ddc3072 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -580,20 +580,20 @@ impl Cursor<'_> { /// if string is terminated. fn double_quoted_string(&mut self) -> bool { debug_assert!(self.prev() == '"'); - loop { - match self.nth_char(0) { + while let Some(c) = self.bump() { + match c { '"' => { - self.bump(); return true; } - EOF_CHAR if self.is_eof() => return false, - '\\' if self.nth_char(1) == '\\' || self.nth_char(1) == '"' => { + '\\' if self.first() == '\\' || self.first() == '"' => { + // Bump again to skip escaped character. self.bump(); } _ => (), } - self.bump(); } + // End of file reached. + false } /// Eats the double-quoted string and returns a tuple of