Skip to content

rustc_lexer: typo fix + small cleanups #142118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_lexer/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> Cursor<'a> {

/// Peeks the third symbol from the input stream without consuming it.
pub fn third(&self) -> char {
// `.next()` optimizes better than `.nth(1)`
// `.next()` optimizes better than `.nth(2)`
let mut iter = self.chars.clone();
iter.next();
iter.next();
Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ mod cursor;
#[cfg(test)]
mod tests;

use LiteralKind::*;
use TokenKind::*;
use cursor::EOF_CHAR;
pub use cursor::{Cursor, FrontmatterAllowed};
use unicode_properties::UnicodeEmoji;
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;

use self::LiteralKind::*;
use self::TokenKind::*;
use crate::cursor::EOF_CHAR;
pub use crate::cursor::{Cursor, FrontmatterAllowed};

/// Parsed token.
/// It doesn't contain information about data that has been parsed,
/// only the type of the token and its size.
Expand Down Expand Up @@ -372,9 +371,8 @@ pub fn is_ident(string: &str) -> bool {
impl Cursor<'_> {
/// Parses a token from the input string.
pub fn advance_token(&mut self) -> Token {
let first_char = match self.bump() {
Some(c) => c,
None => return Token::new(TokenKind::Eof, 0),
let Some(first_char) = self.bump() else {
return Token::new(TokenKind::Eof, 0);
};

let token_kind = match first_char {
Expand Down Expand Up @@ -788,7 +786,7 @@ impl Cursor<'_> {
} else {
// No base prefix, parse number in the usual way.
self.eat_decimal_digits();
};
}

match self.first() {
// Don't be greedy if this is actually an
Expand Down
Loading