@@ -297,8 +297,8 @@ impl TokenType {
297
297
}
298
298
}
299
299
300
- fn is_plain_ident_or_underscore ( t : & token:: Token ) -> bool {
301
- t. is_plain_ident ( ) || * t == token:: Underscore
300
+ fn is_ident_or_underscore ( t : & token:: Token ) -> bool {
301
+ t. is_ident ( ) || * t == token:: Underscore
302
302
}
303
303
304
304
/// Information about the path to a module.
@@ -585,14 +585,6 @@ impl<'a> Parser<'a> {
585
585
}
586
586
}
587
587
588
- pub fn parse_ident_or_self_type ( & mut self ) -> PResult < ' a , ast:: Ident > {
589
- if self . is_self_type_ident ( ) {
590
- self . expect_self_type_ident ( )
591
- } else {
592
- self . parse_ident ( )
593
- }
594
- }
595
-
596
588
/// Check if the next token is `tok`, and return `true` if so.
597
589
///
598
590
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
@@ -1476,9 +1468,7 @@ impl<'a> Parser<'a> {
1476
1468
self . parse_qualified_path ( NoTypesAllowed ) ?;
1477
1469
1478
1470
TyKind :: Path ( Some ( qself) , path)
1479
- } else if self . check ( & token:: ModSep ) ||
1480
- self . token . is_ident ( ) ||
1481
- self . token . is_path ( ) {
1471
+ } else if self . is_path_start ( ) {
1482
1472
let path = self . parse_path ( LifetimeAndTypesWithoutColons ) ?;
1483
1473
if self . check ( & token:: Not ) {
1484
1474
// MACRO INVOCATION
@@ -1541,10 +1531,10 @@ impl<'a> Parser<'a> {
1541
1531
debug ! ( "parser is_named_argument offset:{}" , offset) ;
1542
1532
1543
1533
if offset == 0 {
1544
- is_plain_ident_or_underscore ( & self . token )
1534
+ is_ident_or_underscore ( & self . token )
1545
1535
&& self . look_ahead ( 1 , |t| * t == token:: Colon )
1546
1536
} else {
1547
- self . look_ahead ( offset, |t| is_plain_ident_or_underscore ( t) )
1537
+ self . look_ahead ( offset, |t| is_ident_or_underscore ( t) )
1548
1538
&& self . look_ahead ( offset + 1 , |t| * t == token:: Colon )
1549
1539
}
1550
1540
}
@@ -1707,6 +1697,16 @@ impl<'a> Parser<'a> {
1707
1697
}
1708
1698
}
1709
1699
1700
+ pub fn parse_path_segment_ident ( & mut self ) -> PResult < ' a , ast:: Ident > {
1701
+ match self . token {
1702
+ token:: Ident ( sid, _) if self . token . is_path_segment_keyword ( ) => {
1703
+ self . bump ( ) ;
1704
+ Ok ( sid)
1705
+ }
1706
+ _ => self . parse_ident ( ) ,
1707
+ }
1708
+ }
1709
+
1710
1710
/// Parses qualified path.
1711
1711
///
1712
1712
/// Assumes that the leading `<` has been parsed already.
@@ -1813,7 +1813,7 @@ impl<'a> Parser<'a> {
1813
1813
let mut segments = Vec :: new ( ) ;
1814
1814
loop {
1815
1815
// First, parse an identifier.
1816
- let identifier = self . parse_ident_or_self_type ( ) ?;
1816
+ let identifier = self . parse_path_segment_ident ( ) ?;
1817
1817
1818
1818
// Parse types, optionally.
1819
1819
let parameters = if self . eat_lt ( ) {
@@ -1866,7 +1866,7 @@ impl<'a> Parser<'a> {
1866
1866
let mut segments = Vec :: new ( ) ;
1867
1867
loop {
1868
1868
// First, parse an identifier.
1869
- let identifier = self . parse_ident_or_self_type ( ) ?;
1869
+ let identifier = self . parse_path_segment_ident ( ) ?;
1870
1870
1871
1871
// If we do not see a `::`, stop.
1872
1872
if !self . eat ( & token:: ModSep ) {
@@ -1913,7 +1913,7 @@ impl<'a> Parser<'a> {
1913
1913
let mut segments = Vec :: new ( ) ;
1914
1914
loop {
1915
1915
// First, parse an identifier.
1916
- let identifier = self . parse_ident_or_self_type ( ) ?;
1916
+ let identifier = self . parse_path_segment_ident ( ) ?;
1917
1917
1918
1918
// Assemble and push the result.
1919
1919
segments. push ( ast:: PathSegment {
@@ -2212,15 +2212,6 @@ impl<'a> Parser<'a> {
2212
2212
let lo = self . span . lo ;
2213
2213
return self . parse_lambda_expr ( lo, CaptureBy :: Ref , attrs) ;
2214
2214
} ,
2215
- token:: Ident ( id @ ast:: Ident {
2216
- name : token:: SELF_KEYWORD_NAME ,
2217
- ctxt : _
2218
- } , token:: Plain ) => {
2219
- self . bump ( ) ;
2220
- let path = ast:: Path :: from_ident ( mk_sp ( lo, hi) , id) ;
2221
- ex = ExprKind :: Path ( None , path) ;
2222
- hi = self . last_span . hi ;
2223
- }
2224
2215
token:: OpenDelim ( token:: Bracket ) => {
2225
2216
self . bump ( ) ;
2226
2217
@@ -2350,12 +2341,8 @@ impl<'a> Parser<'a> {
2350
2341
let mut db = self . fatal ( "expected expression, found statement (`let`)" ) ;
2351
2342
db. note ( "variable declaration using `let` is a statement" ) ;
2352
2343
return Err ( db) ;
2353
- } else if self . check ( & token:: ModSep ) ||
2354
- self . token . is_ident ( ) &&
2355
- !self . check_keyword ( keywords:: True ) &&
2356
- !self . check_keyword ( keywords:: False ) {
2357
- let pth =
2358
- self . parse_path ( LifetimeAndTypesWithColons ) ?;
2344
+ } else if self . is_path_start ( ) {
2345
+ let pth = self . parse_path ( LifetimeAndTypesWithColons ) ?;
2359
2346
2360
2347
// `!`, as an operator, is prefix, so we know this isn't that
2361
2348
if self . check ( & token:: Not ) {
@@ -2694,7 +2681,7 @@ impl<'a> Parser<'a> {
2694
2681
op : repeat,
2695
2682
num_captures : name_num
2696
2683
} ) ) ) ;
2697
- } else if self . token . is_keyword_allow_following_colon ( keywords:: Crate ) {
2684
+ } else if self . token . is_keyword ( keywords:: Crate ) {
2698
2685
self . bump ( ) ;
2699
2686
return Ok ( TokenTree :: Token ( sp, SpecialVarNt ( SpecialMacroVar :: CrateMacroVar ) ) ) ;
2700
2687
} else {
@@ -3663,10 +3650,9 @@ impl<'a> Parser<'a> {
3663
3650
pat = PatKind :: Box ( subpat) ;
3664
3651
} else if self . is_path_start ( ) {
3665
3652
// Parse pattern starting with a path
3666
- if self . token . is_plain_ident ( ) && self . look_ahead ( 1 , |t| * t != token:: DotDotDot &&
3653
+ if self . token . is_ident ( ) && self . look_ahead ( 1 , |t| * t != token:: DotDotDot &&
3667
3654
* t != token:: OpenDelim ( token:: Brace ) &&
3668
3655
* t != token:: OpenDelim ( token:: Paren ) &&
3669
- // Contrary to its definition, a plain ident can be followed by :: in macros
3670
3656
* t != token:: ModSep ) {
3671
3657
// Plain idents have some extra abilities here compared to general paths
3672
3658
if self . look_ahead ( 1 , |t| * t == token:: Not ) {
@@ -4626,16 +4612,9 @@ impl<'a> Parser<'a> {
4626
4612
} ) )
4627
4613
}
4628
4614
4629
- fn is_self_ident ( & mut self ) -> bool {
4630
- match self . token {
4631
- token:: Ident ( id, token:: Plain ) => id. name == special_idents:: self_. name ,
4632
- _ => false
4633
- }
4634
- }
4635
-
4636
4615
fn expect_self_ident ( & mut self ) -> PResult < ' a , ast:: Ident > {
4637
4616
match self . token {
4638
- token:: Ident ( id, token :: Plain ) if id. name == special_idents:: self_. name => {
4617
+ token:: Ident ( id, _ ) if id. name == special_idents:: self_. name => {
4639
4618
self . bump ( ) ;
4640
4619
Ok ( id)
4641
4620
} ,
@@ -4647,27 +4626,6 @@ impl<'a> Parser<'a> {
4647
4626
}
4648
4627
}
4649
4628
4650
- fn is_self_type_ident ( & mut self ) -> bool {
4651
- match self . token {
4652
- token:: Ident ( id, token:: Plain ) => id. name == special_idents:: type_self. name ,
4653
- _ => false
4654
- }
4655
- }
4656
-
4657
- fn expect_self_type_ident ( & mut self ) -> PResult < ' a , ast:: Ident > {
4658
- match self . token {
4659
- token:: Ident ( id, token:: Plain ) if id. name == special_idents:: type_self. name => {
4660
- self . bump ( ) ;
4661
- Ok ( id)
4662
- } ,
4663
- _ => {
4664
- let token_str = self . this_token_to_string ( ) ;
4665
- Err ( self . fatal ( & format ! ( "expected `Self`, found `{}`" ,
4666
- token_str) ) )
4667
- }
4668
- }
4669
- }
4670
-
4671
4629
/// Parse the argument list and result type of a function
4672
4630
/// that may have a self type.
4673
4631
fn parse_fn_decl_with_self < F > ( & mut self ,
@@ -4736,7 +4694,7 @@ impl<'a> Parser<'a> {
4736
4694
} else {
4737
4695
Mutability :: Immutable
4738
4696
} ;
4739
- if self . is_self_ident ( ) {
4697
+ if self . token . is_keyword ( keywords :: SelfValue ) {
4740
4698
let span = self . span ;
4741
4699
self . span_err ( span, "cannot pass self by raw pointer" ) ;
4742
4700
self . bump ( ) ;
@@ -4745,7 +4703,7 @@ impl<'a> Parser<'a> {
4745
4703
SelfKind :: Value ( special_idents:: self_)
4746
4704
}
4747
4705
token:: Ident ( ..) => {
4748
- if self . is_self_ident ( ) {
4706
+ if self . token . is_keyword ( keywords :: SelfValue ) {
4749
4707
let self_ident = self . expect_self_ident ( ) ?;
4750
4708
4751
4709
// Determine whether this is the fully explicit form, `self:
@@ -6044,7 +6002,7 @@ impl<'a> Parser<'a> {
6044
6002
) -> PResult < ' a , Option < P < Item > > > {
6045
6003
if macros_allowed && !self . token . is_any_keyword ( )
6046
6004
&& self . look_ahead ( 1 , |t| * t == token:: Not )
6047
- && ( self . look_ahead ( 2 , |t| t. is_plain_ident ( ) )
6005
+ && ( self . look_ahead ( 2 , |t| t. is_ident ( ) )
6048
6006
|| self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Paren ) )
6049
6007
|| self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) ) {
6050
6008
// MACRO INVOCATION ITEM
@@ -6061,7 +6019,7 @@ impl<'a> Parser<'a> {
6061
6019
// a 'special' identifier (like what `macro_rules!` uses)
6062
6020
// is optional. We should eventually unify invoc syntax
6063
6021
// and remove this.
6064
- let id = if self . token . is_plain_ident ( ) {
6022
+ let id = if self . token . is_ident ( ) {
6065
6023
self . parse_ident ( ) ?
6066
6024
} else {
6067
6025
token:: special_idents:: invalid // no special identifier
0 commit comments