@@ -335,18 +335,6 @@ impl TokenType {
335335 }
336336}
337337
338- /// Used by [`Parser::expect_any_with_type`].
339- #[ derive( Copy , Clone , Debug ) ]
340- enum TokenExpectType {
341- /// Unencountered tokens are inserted into [`Parser::expected_tokens`].
342- /// See [`Parser::check`].
343- Expect ,
344-
345- /// Unencountered tokens are not inserted into [`Parser::expected_tokens`].
346- /// See [`Parser::check_noexpect`].
347- NoExpect ,
348- }
349-
350338/// A sequence separator.
351339#[ derive( Debug ) ]
352340struct SeqSep {
@@ -807,29 +795,31 @@ impl<'a> Parser<'a> {
807795 }
808796
809797 /// Checks if the next token is contained within `kets`, and returns `true` if so.
810- fn expect_any_with_type ( & mut self , kets : & [ & TokenKind ] , expect : TokenExpectType ) -> bool {
811- kets. iter ( ) . any ( |k| match expect {
812- TokenExpectType :: Expect => self . check ( k) ,
813- TokenExpectType :: NoExpect => self . check_noexpect ( k) ,
814- } )
798+ fn expect_any_with_type (
799+ & mut self ,
800+ kets_expected : & [ & TokenKind ] ,
801+ kets_not_expected : & [ & TokenKind ] ,
802+ ) -> bool {
803+ kets_expected. iter ( ) . any ( |k| self . check ( k) )
804+ || kets_not_expected. iter ( ) . any ( |k| self . check_noexpect ( k) )
815805 }
816806
817807 /// Parses a sequence until the specified delimiters. The function
818808 /// `f` must consume tokens until reaching the next separator or
819809 /// closing bracket.
820810 fn parse_seq_to_before_tokens < T > (
821811 & mut self ,
822- kets : & [ & TokenKind ] ,
812+ kets_expected : & [ & TokenKind ] ,
813+ kets_not_expected : & [ & TokenKind ] ,
823814 sep : SeqSep ,
824- expect : TokenExpectType ,
825815 mut f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
826816 ) -> PResult < ' a , ( ThinVec < T > , Trailing , Recovered ) > {
827817 let mut first = true ;
828818 let mut recovered = Recovered :: No ;
829819 let mut trailing = Trailing :: No ;
830820 let mut v = ThinVec :: new ( ) ;
831821
832- while !self . expect_any_with_type ( kets , expect ) {
822+ while !self . expect_any_with_type ( kets_expected , kets_not_expected ) {
833823 if let token:: CloseDelim ( ..) | token:: Eof = self . token . kind {
834824 break ;
835825 }
@@ -927,7 +917,8 @@ impl<'a> Parser<'a> {
927917 if self . token == token:: Colon {
928918 // we will try to recover in `maybe_recover_struct_lit_bad_delims`
929919 return Err ( expect_err) ;
930- } else if let [ token:: CloseDelim ( Delimiter :: Parenthesis ) ] = kets
920+ } else if let [ token:: CloseDelim ( Delimiter :: Parenthesis ) ] =
921+ kets_expected
931922 {
932923 return Err ( expect_err) ;
933924 } else {
@@ -940,7 +931,9 @@ impl<'a> Parser<'a> {
940931 }
941932 }
942933 }
943- if sep. trailing_sep_allowed && self . expect_any_with_type ( kets, expect) {
934+ if sep. trailing_sep_allowed
935+ && self . expect_any_with_type ( kets_expected, kets_not_expected)
936+ {
944937 trailing = Trailing :: Yes ;
945938 break ;
946939 }
@@ -1020,7 +1013,7 @@ impl<'a> Parser<'a> {
10201013 sep : SeqSep ,
10211014 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
10221015 ) -> PResult < ' a , ( ThinVec < T > , Trailing , Recovered ) > {
1023- self . parse_seq_to_before_tokens ( & [ ket] , sep , TokenExpectType :: Expect , f)
1016+ self . parse_seq_to_before_tokens ( & [ ket] , & [ ] , sep , f)
10241017 }
10251018
10261019 /// Parses a sequence, including only the closing delimiter. The function
0 commit comments