@@ -248,7 +248,7 @@ impl Cursor<'_> {
248
248
let first_char = self . bump ( ) . unwrap ( ) ;
249
249
let token_kind = match first_char {
250
250
// Slash, comment or block comment.
251
- '/' => match self . nth_char ( 0 ) {
251
+ '/' => match self . first ( ) {
252
252
'/' => self . line_comment ( ) ,
253
253
'*' => self . block_comment ( ) ,
254
254
_ => Slash ,
@@ -257,8 +257,8 @@ impl Cursor<'_> {
257
257
// Whitespace sequence.
258
258
c if is_whitespace ( c) => self . whitespace ( ) ,
259
259
260
- // Raw string literal or identifier.
261
- 'r' => match ( self . nth_char ( 0 ) , self . nth_char ( 1 ) ) {
260
+ // Raw identifier, raw string literal or identifier.
261
+ 'r' => match ( self . first ( ) , self . second ( ) ) {
262
262
( '#' , c1) if is_id_start ( c1) => self . raw_ident ( ) ,
263
263
( '#' , _) | ( '"' , _) => {
264
264
let ( n_hashes, started, terminated) = self . raw_double_quoted_string ( ) ;
@@ -273,7 +273,7 @@ impl Cursor<'_> {
273
273
} ,
274
274
275
275
// Byte literal, byte string literal, raw byte string literal or identifier.
276
- 'b' => match ( self . nth_char ( 0 ) , self . nth_char ( 1 ) ) {
276
+ 'b' => match ( self . first ( ) , self . second ( ) ) {
277
277
( '\'' , _) => {
278
278
self . bump ( ) ;
279
279
let terminated = self . single_quoted_string ( ) ;
@@ -366,7 +366,7 @@ impl Cursor<'_> {
366
366
}
367
367
368
368
fn line_comment ( & mut self ) -> TokenKind {
369
- debug_assert ! ( self . prev( ) == '/' && self . nth_char ( 0 ) == '/' ) ;
369
+ debug_assert ! ( self . prev( ) == '/' && self . first ( ) == '/' ) ;
370
370
self . bump ( ) ;
371
371
loop {
372
372
match self . nth_char ( 0 ) {
@@ -381,16 +381,16 @@ impl Cursor<'_> {
381
381
}
382
382
383
383
fn block_comment ( & mut self ) -> TokenKind {
384
- debug_assert ! ( self . prev( ) == '/' && self . nth_char ( 0 ) == '*' ) ;
384
+ debug_assert ! ( self . prev( ) == '/' && self . first ( ) == '*' ) ;
385
385
self . bump ( ) ;
386
386
let mut depth = 1usize ;
387
387
while let Some ( c) = self . bump ( ) {
388
388
match c {
389
- '/' if self . nth_char ( 0 ) == '*' => {
389
+ '/' if self . first ( ) == '*' => {
390
390
self . bump ( ) ;
391
391
depth += 1 ;
392
392
}
393
- '*' if self . nth_char ( 0 ) == '/' => {
393
+ '*' if self . first ( ) == '/' => {
394
394
self . bump ( ) ;
395
395
depth -= 1 ;
396
396
if depth == 0 {
@@ -418,8 +418,8 @@ impl Cursor<'_> {
418
418
fn raw_ident ( & mut self ) -> TokenKind {
419
419
debug_assert ! (
420
420
self . prev( ) == 'r'
421
- && self . nth_char ( 0 ) == '#'
422
- && is_id_start( self . nth_char ( 1 ) )
421
+ && self . first ( ) == '#'
422
+ && is_id_start( self . second ( ) )
423
423
) ;
424
424
self . bump ( ) ;
425
425
self . bump ( ) ;
@@ -442,7 +442,7 @@ impl Cursor<'_> {
442
442
let mut base = Base :: Decimal ;
443
443
if first_digit == '0' {
444
444
// Attempt to parse encoding base.
445
- let has_digits = match self . nth_char ( 0 ) {
445
+ let has_digits = match self . first ( ) {
446
446
'b' => {
447
447
base = Base :: Binary ;
448
448
self . bump ( ) ;
@@ -476,20 +476,20 @@ impl Cursor<'_> {
476
476
self . eat_decimal_digits ( ) ;
477
477
} ;
478
478
479
- match self . nth_char ( 0 ) {
479
+ match self . first ( ) {
480
480
// Don't be greedy if this is actually an
481
481
// integer literal followed by field/method access or a range pattern
482
482
// (`0..2` and `12.foo()`)
483
- '.' if self . nth_char ( 1 ) != '.'
484
- && !is_id_start ( self . nth_char ( 1 ) ) =>
483
+ '.' if self . second ( ) != '.'
484
+ && !is_id_start ( self . second ( ) ) =>
485
485
{
486
486
// might have stuff after the ., and if it does, it needs to start
487
487
// with a number
488
488
self . bump ( ) ;
489
489
let mut empty_exponent = false ;
490
- if self . nth_char ( 0 ) . is_digit ( 10 ) {
490
+ if self . first ( ) . is_digit ( 10 ) {
491
491
self . eat_decimal_digits ( ) ;
492
- match self . nth_char ( 0 ) {
492
+ match self . first ( ) {
493
493
'e' | 'E' => {
494
494
self . bump ( ) ;
495
495
empty_exponent = self . float_exponent ( ) . is_err ( )
@@ -556,7 +556,7 @@ impl Cursor<'_> {
556
556
// Parse until either quotes are terminated or error is detected.
557
557
let mut first = true ;
558
558
loop {
559
- match self . nth_char ( 0 ) {
559
+ match self . first ( ) {
560
560
// Probably beginning of the comment, which we don't want to include
561
561
// to the error report.
562
562
'/' if !first => break ,
@@ -643,7 +643,7 @@ impl Cursor<'_> {
643
643
fn eat_decimal_digits ( & mut self ) -> bool {
644
644
let mut has_digits = false ;
645
645
loop {
646
- match self . nth_char ( 0 ) {
646
+ match self . first ( ) {
647
647
'_' => {
648
648
self . bump ( ) ;
649
649
}
@@ -660,7 +660,7 @@ impl Cursor<'_> {
660
660
fn eat_hexadecimal_digits ( & mut self ) -> bool {
661
661
let mut has_digits = false ;
662
662
loop {
663
- match self . nth_char ( 0 ) {
663
+ match self . first ( ) {
664
664
'_' => {
665
665
self . bump ( ) ;
666
666
}
@@ -676,7 +676,7 @@ impl Cursor<'_> {
676
676
677
677
fn float_exponent ( & mut self ) -> Result < ( ) , ( ) > {
678
678
debug_assert ! ( self . prev( ) == 'e' || self . prev( ) == 'E' ) ;
679
- if self . nth_char ( 0 ) == '-' || self . nth_char ( 0 ) == '+' {
679
+ if self . first ( ) == '-' || self . first ( ) == '+' {
680
680
self . bump ( ) ;
681
681
}
682
682
if self . eat_decimal_digits ( ) { Ok ( ( ) ) } else { Err ( ( ) ) }
0 commit comments