@@ -474,8 +474,8 @@ impl<'a> Parser<'a> {
474
474
// If this isn't the case however, and the suggestion is a token the
475
475
// content of which is the same as the found token's, we remove it as well.
476
476
if !eq {
477
- if let TokenType :: Token ( kind) = & token {
478
- if kind == & self . token . kind {
477
+ if let TokenType :: Token ( kind) = token {
478
+ if self . token == * kind {
479
479
return false ;
480
480
}
481
481
}
@@ -506,7 +506,7 @@ impl<'a> Parser<'a> {
506
506
} else if !sm. is_multiline ( self . prev_token . span . until ( self . token . span ) ) {
507
507
// The current token is in the same line as the prior token, not recoverable.
508
508
} else if [ token:: Comma , token:: Colon ] . contains ( & self . token . kind )
509
- && self . prev_token . kind == token:: CloseDelim ( Delimiter :: Parenthesis )
509
+ && self . prev_token == token:: CloseDelim ( Delimiter :: Parenthesis )
510
510
{
511
511
// Likely typo: The current token is on a new line and is expected to be
512
512
// `.`, `;`, `?`, or an operator after a close delimiter token.
@@ -562,7 +562,7 @@ impl<'a> Parser<'a> {
562
562
}
563
563
}
564
564
565
- if self . token . kind == TokenKind :: EqEq
565
+ if self . token == TokenKind :: EqEq
566
566
&& self . prev_token . is_ident ( )
567
567
&& expected. iter ( ) . any ( |tok| matches ! ( tok, TokenType :: Token ( TokenKind :: Eq ) ) )
568
568
{
@@ -655,9 +655,9 @@ impl<'a> Parser<'a> {
655
655
// positive for a `cr#` that wasn't intended to start a c-string literal, but identifying
656
656
// that in the parser requires unbounded lookahead, so we only add a hint to the existing
657
657
// error rather than replacing it entirely.
658
- if ( ( self . prev_token . kind == TokenKind :: Ident ( sym:: c, IdentIsRaw :: No )
658
+ if ( ( self . prev_token == TokenKind :: Ident ( sym:: c, IdentIsRaw :: No )
659
659
&& matches ! ( & self . token. kind, TokenKind :: Literal ( token:: Lit { kind: token:: Str , .. } ) ) )
660
- || ( self . prev_token . kind == TokenKind :: Ident ( sym:: cr, IdentIsRaw :: No )
660
+ || ( self . prev_token == TokenKind :: Ident ( sym:: cr, IdentIsRaw :: No )
661
661
&& matches ! (
662
662
& self . token. kind,
663
663
TokenKind :: Literal ( token:: Lit { kind: token:: Str , .. } ) | token:: Pound
@@ -673,7 +673,7 @@ impl<'a> Parser<'a> {
673
673
// `pub` may be used for an item or `pub(crate)`
674
674
if self . prev_token . is_ident_named ( sym:: public)
675
675
&& ( self . token . can_begin_item ( )
676
- || self . token . kind == TokenKind :: OpenDelim ( Delimiter :: Parenthesis ) )
676
+ || self . token == TokenKind :: OpenDelim ( Delimiter :: Parenthesis ) )
677
677
{
678
678
err. span_suggestion_short (
679
679
self . prev_token . span ,
@@ -772,7 +772,7 @@ impl<'a> Parser<'a> {
772
772
) ,
773
773
) ;
774
774
if self . token == token:: Pound
775
- && self . look_ahead ( 1 , |t| t . kind == token:: OpenDelim ( Delimiter :: Bracket ) )
775
+ && self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( Delimiter :: Bracket ) )
776
776
{
777
777
// We have
778
778
// #[attr]
@@ -867,7 +867,7 @@ impl<'a> Parser<'a> {
867
867
let str_span = self . prev_token . span ;
868
868
let mut span = self . token . span ;
869
869
let mut count = 0 ;
870
- while self . token . kind == TokenKind :: Pound
870
+ while self . token == TokenKind :: Pound
871
871
&& !sm. is_multiline ( span. shrink_to_hi ( ) . until ( self . token . span . shrink_to_lo ( ) ) )
872
872
{
873
873
span = span. with_hi ( self . token . span . hi ( ) ) ;
@@ -1167,7 +1167,7 @@ impl<'a> Parser<'a> {
1167
1167
return ;
1168
1168
}
1169
1169
1170
- if token:: PathSep == self . token . kind && segment. args . is_none ( ) {
1170
+ if self . token == token:: PathSep && segment. args . is_none ( ) {
1171
1171
let snapshot = self . create_snapshot_for_diagnostic ( ) ;
1172
1172
self . bump ( ) ;
1173
1173
let lo = self . token . span ;
@@ -1176,13 +1176,11 @@ impl<'a> Parser<'a> {
1176
1176
let span = lo. to ( self . prev_token . span ) ;
1177
1177
// Detect trailing `>` like in `x.collect::Vec<_>>()`.
1178
1178
let mut trailing_span = self . prev_token . span . shrink_to_hi ( ) ;
1179
- while self . token . kind == token:: BinOp ( token:: Shr )
1180
- || self . token . kind == token:: Gt
1181
- {
1179
+ while self . token == token:: BinOp ( token:: Shr ) || self . token == token:: Gt {
1182
1180
trailing_span = trailing_span. to ( self . token . span ) ;
1183
1181
self . bump ( ) ;
1184
1182
}
1185
- if self . token . kind == token:: OpenDelim ( Delimiter :: Parenthesis ) {
1183
+ if self . token == token:: OpenDelim ( Delimiter :: Parenthesis ) {
1186
1184
// Recover from bad turbofish: `foo.collect::Vec<_>()`.
1187
1185
segment. args = Some ( AngleBracketedArgs { args, span } . into ( ) ) ;
1188
1186
@@ -1430,7 +1428,7 @@ impl<'a> Parser<'a> {
1430
1428
self . restore_snapshot ( snapshot) ;
1431
1429
}
1432
1430
}
1433
- return if token:: PathSep == self . token . kind {
1431
+ return if self . token == token:: PathSep {
1434
1432
// We have some certainty that this was a bad turbofish at this point.
1435
1433
// `foo< bar >::`
1436
1434
if let ExprKind :: Binary ( o, ..) = inner_op. kind
@@ -1462,7 +1460,7 @@ impl<'a> Parser<'a> {
1462
1460
Err ( self . dcx ( ) . create_err ( err) )
1463
1461
}
1464
1462
}
1465
- } else if token:: OpenDelim ( Delimiter :: Parenthesis ) == self . token . kind {
1463
+ } else if self . token == token :: OpenDelim ( Delimiter :: Parenthesis ) {
1466
1464
// We have high certainty that this was a bad turbofish at this point.
1467
1465
// `foo< bar >(`
1468
1466
if let ExprKind :: Binary ( o, ..) = inner_op. kind
@@ -1528,7 +1526,7 @@ impl<'a> Parser<'a> {
1528
1526
] ;
1529
1527
self . consume_tts ( 1 , & modifiers) ;
1530
1528
1531
- if self . token . kind == token:: Eof {
1529
+ if self . token == token:: Eof {
1532
1530
// Not entirely sure that what we consumed were fn arguments, rollback.
1533
1531
self . restore_snapshot ( snapshot) ;
1534
1532
Err ( ( ) )
@@ -2405,10 +2403,10 @@ impl<'a> Parser<'a> {
2405
2403
modifier : & [ ( token:: TokenKind , i64 ) ] ,
2406
2404
) {
2407
2405
while acc > 0 {
2408
- if let Some ( ( _, val) ) = modifier. iter ( ) . find ( |( t, _) | * t == self . token . kind ) {
2406
+ if let Some ( ( _, val) ) = modifier. iter ( ) . find ( |( t, _) | self . token == * t ) {
2409
2407
acc += * val;
2410
2408
}
2411
- if self . token . kind == token:: Eof {
2409
+ if self . token == token:: Eof {
2412
2410
break ;
2413
2411
}
2414
2412
self . bump ( ) ;
@@ -2598,7 +2596,7 @@ impl<'a> Parser<'a> {
2598
2596
}
2599
2597
} )
2600
2598
. is_some ( )
2601
- || self . token . kind == TokenKind :: Dot ;
2599
+ || self . token == TokenKind :: Dot ;
2602
2600
// This will be true when a trait object type `Foo +` or a path which was a `const fn` with
2603
2601
// type params has been parsed.
2604
2602
let was_op =
@@ -2617,7 +2615,7 @@ impl<'a> Parser<'a> {
2617
2615
} ) ( ) {
2618
2616
Ok ( expr) => {
2619
2617
// Find a mistake like `MyTrait<Assoc == S::Assoc>`.
2620
- if token:: EqEq == snapshot . token . kind {
2618
+ if snapshot . token == token:: EqEq {
2621
2619
err. span_suggestion (
2622
2620
snapshot. token . span ,
2623
2621
"if you meant to use an associated type binding, replace `==` with `=`" ,
@@ -2627,7 +2625,7 @@ impl<'a> Parser<'a> {
2627
2625
let guar = err. emit ( ) ;
2628
2626
let value = self . mk_expr_err ( start. to ( expr. span ) , guar) ;
2629
2627
return Ok ( GenericArg :: Const ( AnonConst { id : ast:: DUMMY_NODE_ID , value } ) ) ;
2630
- } else if token:: Colon == snapshot . token . kind
2628
+ } else if snapshot . token == token:: Colon
2631
2629
&& expr. span . lo ( ) == snapshot. token . span . hi ( )
2632
2630
&& matches ! ( expr. kind, ExprKind :: Path ( ..) )
2633
2631
{
@@ -2642,8 +2640,7 @@ impl<'a> Parser<'a> {
2642
2640
return Ok ( GenericArg :: Type (
2643
2641
self . mk_ty ( start. to ( expr. span ) , TyKind :: Err ( guar) ) ,
2644
2642
) ) ;
2645
- } else if token:: Comma == self . token . kind || self . token . kind . should_end_const_arg ( )
2646
- {
2643
+ } else if self . token == token:: Comma || self . token . kind . should_end_const_arg ( ) {
2647
2644
// Avoid the following output by checking that we consumed a full const arg:
2648
2645
// help: expressions must be enclosed in braces to be used as const generic
2649
2646
// arguments
@@ -2846,8 +2843,8 @@ impl<'a> Parser<'a> {
2846
2843
pub ( crate ) fn maybe_recover_unexpected_block_label ( & mut self ) -> bool {
2847
2844
// Check for `'a : {`
2848
2845
if !( self . check_lifetime ( )
2849
- && self . look_ahead ( 1 , |tok| tok . kind == token:: Colon )
2850
- && self . look_ahead ( 2 , |tok| tok . kind == token:: OpenDelim ( Delimiter :: Brace ) ) )
2846
+ && self . look_ahead ( 1 , |t| * t == token:: Colon )
2847
+ && self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( Delimiter :: Brace ) ) )
2851
2848
{
2852
2849
return false ;
2853
2850
}
@@ -3001,7 +2998,7 @@ impl<'a> Parser<'a> {
3001
2998
// >>>>>>>
3002
2999
let mut end = None ;
3003
3000
loop {
3004
- if self . token . kind == TokenKind :: Eof {
3001
+ if self . token == TokenKind :: Eof {
3005
3002
break ;
3006
3003
}
3007
3004
if let Some ( span) = self . conflict_marker ( & TokenKind :: OrOr , & TokenKind :: BinOp ( token:: Or ) )
0 commit comments