1
1
use rustc_ast:: token:: { self , Delimiter } ;
2
- use rustc_ast:: tokenstream:: { Cursor , TokenStream , TokenTree } ;
2
+ use rustc_ast:: tokenstream:: { CursorRef , TokenStream , TokenTree } ;
3
3
use rustc_ast:: { LitIntType , LitKind } ;
4
4
use rustc_ast_pretty:: pprust;
5
5
use rustc_errors:: { Applicability , PResult } ;
@@ -71,12 +71,14 @@ impl MetaVarExpr {
71
71
}
72
72
73
73
// 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 , ( ) > {
75
78
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) ) ) ;
80
82
diag. span_note ( tt. span ( ) , "meta-variable expression must not have trailing tokens" ) ;
81
83
Err ( diag)
82
84
} else {
@@ -86,7 +88,7 @@ fn check_trailing_token<'sess>(iter: &mut Cursor, sess: &'sess ParseSess) -> PRe
86
88
87
89
/// Parse a meta-variable `count` expression: `count(ident[, depth])`
88
90
fn parse_count < ' sess > (
89
- iter : & mut Cursor ,
91
+ iter : & mut CursorRef < ' _ > ,
90
92
sess : & ' sess ParseSess ,
91
93
span : Span ,
92
94
) -> PResult < ' sess , MetaVarExpr > {
@@ -97,7 +99,7 @@ fn parse_count<'sess>(
97
99
98
100
/// Parses the depth used by index(depth) and length(depth).
99
101
fn parse_depth < ' sess > (
100
- iter : & mut Cursor ,
102
+ iter : & mut CursorRef < ' _ > ,
101
103
sess : & ' sess ParseSess ,
102
104
span : Span ,
103
105
) -> PResult < ' sess , usize > {
@@ -110,7 +112,7 @@ fn parse_depth<'sess>(
110
112
"meta-variable expression depth must be a literal"
111
113
) ) ;
112
114
} ;
113
- if let Ok ( lit_kind) = LitKind :: from_lit_token ( lit)
115
+ if let Ok ( lit_kind) = LitKind :: from_lit_token ( * lit)
114
116
&& let LitKind :: Int ( n_u128, LitIntType :: Unsuffixed ) = lit_kind
115
117
&& let Ok ( n_usize) = usize:: try_from ( n_u128)
116
118
{
@@ -124,15 +126,15 @@ fn parse_depth<'sess>(
124
126
125
127
/// Parses an generic ident
126
128
fn parse_ident < ' sess > (
127
- iter : & mut Cursor ,
129
+ iter : & mut CursorRef < ' _ > ,
128
130
sess : & ' sess ParseSess ,
129
131
span : Span ,
130
132
) -> PResult < ' sess , Ident > {
131
133
if let Some ( tt) = iter. next ( ) && let TokenTree :: Token ( token) = tt {
132
134
if let Some ( ( elem, false ) ) = token. ident ( ) {
133
135
return Ok ( elem) ;
134
136
}
135
- let token_str = pprust:: token_to_string ( & token) ;
137
+ let token_str = pprust:: token_to_string ( token) ;
136
138
let mut err = sess. span_diagnostic . struct_span_err (
137
139
span,
138
140
& format ! ( "expected identifier, found `{}`" , & token_str)
@@ -150,7 +152,7 @@ fn parse_ident<'sess>(
150
152
151
153
/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
152
154
/// 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 {
154
156
if let Some ( TokenTree :: Token ( token:: Token { kind : token:: Comma , .. } ) ) = iter. look_ahead ( 0 ) {
155
157
let _ = iter. next ( ) ;
156
158
return true ;
0 commit comments