11use rustc_ast:: token:: { self , Delimiter } ;
2- use rustc_ast:: tokenstream:: { Cursor , TokenStream , TokenTree } ;
2+ use rustc_ast:: tokenstream:: { CursorRef , TokenStream , TokenTree } ;
33use rustc_ast:: { LitIntType , LitKind } ;
44use rustc_ast_pretty:: pprust;
55use rustc_errors:: { Applicability , PResult } ;
@@ -71,12 +71,14 @@ impl MetaVarExpr {
7171}
7272
7373// Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
74- fn check_trailing_token < ' sess > ( iter : & mut Cursor , sess : & ' sess ParseSess ) -> PResult < ' sess , ( ) > {
74+ fn check_trailing_token < ' sess > (
75+ iter : & mut CursorRef < ' _ > ,
76+ sess : & ' sess ParseSess ,
77+ ) -> PResult < ' sess , ( ) > {
7578 if let Some ( tt) = iter. next ( ) {
76- let mut diag = sess. span_diagnostic . struct_span_err (
77- tt. span ( ) ,
78- & format ! ( "unexpected token: {}" , pprust:: tt_to_string( & tt) ) ,
79- ) ;
79+ let mut diag = sess
80+ . span_diagnostic
81+ . struct_span_err ( tt. span ( ) , & format ! ( "unexpected token: {}" , pprust:: tt_to_string( tt) ) ) ;
8082 diag. span_note ( tt. span ( ) , "meta-variable expression must not have trailing tokens" ) ;
8183 Err ( diag)
8284 } else {
@@ -86,7 +88,7 @@ fn check_trailing_token<'sess>(iter: &mut Cursor, sess: &'sess ParseSess) -> PRe
8688
8789/// Parse a meta-variable `count` expression: `count(ident[, depth])`
8890fn parse_count < ' sess > (
89- iter : & mut Cursor ,
91+ iter : & mut CursorRef < ' _ > ,
9092 sess : & ' sess ParseSess ,
9193 span : Span ,
9294) -> PResult < ' sess , MetaVarExpr > {
@@ -97,7 +99,7 @@ fn parse_count<'sess>(
9799
98100/// Parses the depth used by index(depth) and length(depth).
99101fn parse_depth < ' sess > (
100- iter : & mut Cursor ,
102+ iter : & mut CursorRef < ' _ > ,
101103 sess : & ' sess ParseSess ,
102104 span : Span ,
103105) -> PResult < ' sess , usize > {
@@ -110,7 +112,7 @@ fn parse_depth<'sess>(
110112 "meta-variable expression depth must be a literal"
111113 ) ) ;
112114 } ;
113- if let Ok ( lit_kind) = LitKind :: from_lit_token ( lit)
115+ if let Ok ( lit_kind) = LitKind :: from_lit_token ( * lit)
114116 && let LitKind :: Int ( n_u128, LitIntType :: Unsuffixed ) = lit_kind
115117 && let Ok ( n_usize) = usize:: try_from ( n_u128)
116118 {
@@ -124,15 +126,15 @@ fn parse_depth<'sess>(
124126
125127/// Parses an generic ident
126128fn parse_ident < ' sess > (
127- iter : & mut Cursor ,
129+ iter : & mut CursorRef < ' _ > ,
128130 sess : & ' sess ParseSess ,
129131 span : Span ,
130132) -> PResult < ' sess , Ident > {
131133 if let Some ( tt) = iter. next ( ) && let TokenTree :: Token ( token) = tt {
132134 if let Some ( ( elem, false ) ) = token. ident ( ) {
133135 return Ok ( elem) ;
134136 }
135- let token_str = pprust:: token_to_string ( & token) ;
137+ let token_str = pprust:: token_to_string ( token) ;
136138 let mut err = sess. span_diagnostic . struct_span_err (
137139 span,
138140 & format ! ( "expected identifier, found `{}`" , & token_str)
@@ -150,7 +152,7 @@ fn parse_ident<'sess>(
150152
151153/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
152154/// iterator is not modified and the result is `false`.
153- fn try_eat_comma ( iter : & mut Cursor ) -> bool {
155+ fn try_eat_comma ( iter : & mut CursorRef < ' _ > ) -> bool {
154156 if let Some ( TokenTree :: Token ( token:: Token { kind : token:: Comma , .. } ) ) = iter. look_ahead ( 0 ) {
155157 let _ = iter. next ( ) ;
156158 return true ;
0 commit comments