@@ -841,9 +841,7 @@ where
841841 /// ```
842842 #[ must_use]
843843 pub fn next_type ( & mut self ) -> Option < TokenStream > {
844- let Some ( first) = self . peek ( ) else {
845- return None ;
846- } ;
844+ let first = self . peek ( ) ?;
847845 if first. is_comma ( ) || first. is_semi ( ) {
848846 return None ;
849847 } ;
@@ -866,13 +864,14 @@ where
866864 /// "Parses" an expression
867865 ///
868866 /// This just means it collects all the tokens that should belong to the
869- /// expression, until it reaches either:
867+ /// expression, until it reaches (outside a group like `()` or `{}`) either:
868+ /// - a `=>`
870869 /// - a `;`
871870 /// - a `,` outside a type
872871 /// - the end of the token stream
873872 ///
874- /// If the token stream is empty, or starts with `,` or `;` [`None`] is
875- /// returned otherwise, [`Some(TokenStream)`](TokenStream) containing
873+ /// If the token stream is empty, or starts with `=>`, `,` or `;` [`None`]
874+ /// is returned otherwise, [`Some(TokenStream)`](TokenStream) containing
876875 /// every token up to but excluding the terminator.
877876 ///
878877 /// ```
@@ -890,6 +889,7 @@ where
890889 pub fn next_expression ( & mut self ) -> Option < TokenStream > {
891890 if self . peek ( ) . is_none ( )
892891 || matches ! ( self . peek( ) , Some ( token) if token. is_comma( ) || token. is_semi( ) )
892+ || self . peek_tt_fat_arrow ( ) . is_some ( )
893893 {
894894 return None ;
895895 }
@@ -902,9 +902,10 @@ where
902902 // <a> * <a>
903903 // <a> => <a>
904904 ' outer: while let Some ( token) = self . peek ( ) {
905- if token. is_semi ( ) || token. is_comma ( ) {
905+ if token. is_semi ( ) || token. is_comma ( ) || self . peek_tt_fat_arrow ( ) . is_some ( ) {
906906 break ;
907907 }
908+ let token = self . peek ( ) . unwrap ( ) ;
908909 if start && token. is_less_than ( ) {
909910 tokens. extend ( mem:: replace (
910911 & mut last,
@@ -1120,7 +1121,7 @@ mod test {
11201121 #[ test]
11211122 fn expr ( ) {
11221123 let mut at = TokenParser :: new (
1123- quote ! { a + b, <Some , Generic , Type >:: something + <a, b> * a < b, "hi" } ,
1124+ quote ! { a + b, <Some , Generic , Type >:: something + <a, b> * a < b, "hi" => hello } ,
11241125 ) ;
11251126 assert_tokens ! ( at. next_expression( ) . unwrap( ) , { a + b } ) ;
11261127 at. next ( ) ;
@@ -1129,6 +1130,9 @@ mod test {
11291130 ) ;
11301131 at. next ( ) ;
11311132 assert_tokens ! ( at. next_expression( ) . unwrap( ) , { "hi" } ) ;
1133+ at. next ( ) ;
1134+ at. next ( ) ;
1135+ assert_tokens ! ( at. next_expression( ) . unwrap( ) , { hello } ) ;
11321136
11331137 let mut at = TokenParser :: from_str ( "1..," ) . unwrap ( ) ;
11341138 let expr: Vec < _ > = at. next_expression ( ) . unwrap ( ) . into_iter ( ) . collect ( ) ;
0 commit comments