@@ -97,15 +97,14 @@ impl<'a> Parser<'a> {
97
97
fn parse_expr_catch_underscore ( & mut self ) -> PResult < ' a , P < Expr > > {
98
98
match self . parse_expr ( ) {
99
99
Ok ( expr) => Ok ( expr) ,
100
- Err ( mut err) => match self . token . kind {
100
+ Err ( mut err) => match self . normalized_token . kind {
101
101
token:: Ident ( name, false )
102
102
if name == kw:: Underscore && self . look_ahead ( 1 , |t| t == & token:: Comma ) =>
103
103
{
104
104
// Special-case handling of `foo(_, _, _)`
105
105
err. emit ( ) ;
106
- let sp = self . token . span ;
107
106
self . bump ( ) ;
108
- Ok ( self . mk_expr ( sp , ExprKind :: Err , AttrVec :: new ( ) ) )
107
+ Ok ( self . mk_expr ( self . prev_token . span , ExprKind :: Err , AttrVec :: new ( ) ) )
109
108
}
110
109
_ => Err ( err) ,
111
110
} ,
@@ -166,7 +165,7 @@ impl<'a> Parser<'a> {
166
165
while let Some ( op) = self . check_assoc_op ( ) {
167
166
// Adjust the span for interpolated LHS to point to the `$lhs` token
168
167
// and not to what it refers to.
169
- let lhs_span = match self . unnormalized_prev_token . kind {
168
+ let lhs_span = match self . prev_token . kind {
170
169
TokenKind :: Interpolated ( ..) => self . prev_span ,
171
170
_ => lhs. span ,
172
171
} ;
@@ -337,7 +336,7 @@ impl<'a> Parser<'a> {
337
336
/// Also performs recovery for `and` / `or` which are mistaken for `&&` and `||` respectively.
338
337
fn check_assoc_op ( & self ) -> Option < Spanned < AssocOp > > {
339
338
Some ( Spanned {
340
- node : match ( AssocOp :: from_token ( & self . token ) , & self . token . kind ) {
339
+ node : match ( AssocOp :: from_token ( & self . token ) , & self . normalized_token . kind ) {
341
340
( Some ( op) , _) => op,
342
341
( None , token:: Ident ( sym:: and, false ) ) => {
343
342
self . error_bad_logical_op ( "and" , "&&" , "conjunction" ) ;
@@ -349,7 +348,7 @@ impl<'a> Parser<'a> {
349
348
}
350
349
_ => return None ,
351
350
} ,
352
- span : self . token . span ,
351
+ span : self . normalized_token . span ,
353
352
} )
354
353
}
355
354
@@ -441,7 +440,7 @@ impl<'a> Parser<'a> {
441
440
let attrs = self . parse_or_use_outer_attributes ( attrs) ?;
442
441
let lo = self . token . span ;
443
442
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
444
- let ( hi, ex) = match self . token . kind {
443
+ let ( hi, ex) = match self . normalized_token . kind {
445
444
token:: Not => self . parse_unary_expr ( lo, UnOp :: Not ) , // `!expr`
446
445
token:: Tilde => self . recover_tilde_expr ( lo) , // `~expr`
447
446
token:: BinOp ( token:: Minus ) => self . parse_unary_expr ( lo, UnOp :: Neg ) , // `-expr`
@@ -527,7 +526,7 @@ impl<'a> Parser<'a> {
527
526
) -> PResult < ' a , ( Span , P < Expr > ) > {
528
527
expr. map ( |e| {
529
528
(
530
- match self . unnormalized_prev_token . kind {
529
+ match self . prev_token . kind {
531
530
TokenKind :: Interpolated ( ..) => self . prev_span ,
532
531
_ => e. span ,
533
532
} ,
@@ -708,7 +707,7 @@ impl<'a> Parser<'a> {
708
707
}
709
708
710
709
fn parse_dot_suffix_expr ( & mut self , lo : Span , base : P < Expr > ) -> PResult < ' a , P < Expr > > {
711
- match self . token . kind {
710
+ match self . normalized_token . kind {
712
711
token:: Ident ( ..) => self . parse_dot_suffix ( base, lo) ,
713
712
token:: Literal ( token:: Lit { kind : token:: Integer , symbol, suffix } ) => {
714
713
Ok ( self . parse_tuple_field_access_expr ( lo, base, symbol, suffix) )
@@ -777,8 +776,8 @@ impl<'a> Parser<'a> {
777
776
field : Symbol ,
778
777
suffix : Option < Symbol > ,
779
778
) -> P < Expr > {
780
- let span = self . token . span ;
781
779
self . bump ( ) ;
780
+ let span = self . prev_token . span ;
782
781
let field = ExprKind :: Field ( base, Ident :: new ( field, span) ) ;
783
782
self . expect_no_suffix ( span, "a tuple index" , suffix) ;
784
783
self . mk_expr ( lo. to ( span) , field, AttrVec :: new ( ) )
@@ -802,7 +801,7 @@ impl<'a> Parser<'a> {
802
801
803
802
/// Assuming we have just parsed `.`, continue parsing into an expression.
804
803
fn parse_dot_suffix ( & mut self , self_arg : P < Expr > , lo : Span ) -> PResult < ' a , P < Expr > > {
805
- if self . token . span . rust_2018 ( ) && self . eat_keyword ( kw:: Await ) {
804
+ if self . normalized_token . span . rust_2018 ( ) && self . eat_keyword ( kw:: Await ) {
806
805
return self . mk_await_expr ( self_arg, lo) ;
807
806
}
808
807
@@ -916,7 +915,7 @@ impl<'a> Parser<'a> {
916
915
// | ^ expected expression
917
916
self . bump ( ) ;
918
917
Ok ( self . mk_expr_err ( self . token . span ) )
919
- } else if self . token . span . rust_2018 ( ) {
918
+ } else if self . normalized_token . span . rust_2018 ( ) {
920
919
// `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
921
920
if self . check_keyword ( kw:: Async ) {
922
921
if self . is_async_block ( ) {
@@ -1346,7 +1345,7 @@ impl<'a> Parser<'a> {
1346
1345
if self . eat_keyword ( kw:: Static ) { Movability :: Static } else { Movability :: Movable } ;
1347
1346
1348
1347
let asyncness =
1349
- if self . token . span . rust_2018 ( ) { self . parse_asyncness ( ) } else { Async :: No } ;
1348
+ if self . normalized_token . span . rust_2018 ( ) { self . parse_asyncness ( ) } else { Async :: No } ;
1350
1349
if asyncness. is_async ( ) {
1351
1350
// Feature-gate `async ||` closures.
1352
1351
self . sess . gated_spans . gate ( sym:: async_closure, self . prev_span ) ;
@@ -1560,9 +1559,8 @@ impl<'a> Parser<'a> {
1560
1559
1561
1560
fn eat_label ( & mut self ) -> Option < Label > {
1562
1561
self . token . lifetime ( ) . map ( |ident| {
1563
- let span = self . token . span ;
1564
1562
self . bump ( ) ;
1565
- Label { ident : Ident :: new ( ident . name , span ) }
1563
+ Label { ident }
1566
1564
} )
1567
1565
}
1568
1566
@@ -1704,7 +1702,7 @@ impl<'a> Parser<'a> {
1704
1702
fn is_try_block ( & self ) -> bool {
1705
1703
self . token . is_keyword ( kw:: Try ) &&
1706
1704
self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
1707
- self . token . span . rust_2018 ( ) &&
1705
+ self . normalized_token . span . rust_2018 ( ) &&
1708
1706
// Prevent `while try {} {}`, `if try {} {} else {}`, etc.
1709
1707
!self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL )
1710
1708
}
@@ -1854,13 +1852,12 @@ impl<'a> Parser<'a> {
1854
1852
1855
1853
/// Use in case of error after field-looking code: `S { foo: () with a }`.
1856
1854
fn find_struct_error_after_field_looking_code ( & self ) -> Option < Field > {
1857
- if let token:: Ident ( name, _) = self . token . kind {
1855
+ if let token:: Ident ( name, _) = self . normalized_token . kind {
1858
1856
if !self . token . is_reserved_ident ( ) && self . look_ahead ( 1 , |t| * t == token:: Colon ) {
1859
- let span = self . token . span ;
1860
1857
return Some ( ast:: Field {
1861
- ident : Ident :: new ( name, span) ,
1862
- span,
1863
- expr : self . mk_expr_err ( span) ,
1858
+ ident : Ident :: new ( name, self . normalized_token . span ) ,
1859
+ span : self . token . span ,
1860
+ expr : self . mk_expr_err ( self . token . span ) ,
1864
1861
is_shorthand : false ,
1865
1862
attrs : AttrVec :: new ( ) ,
1866
1863
id : DUMMY_NODE_ID ,
0 commit comments