@@ -10,7 +10,7 @@ use crate::parse::token;
10
10
use crate :: ptr:: P ;
11
11
use crate :: symbol:: { kw, sym, Ident , Symbol } ;
12
12
use crate :: { ThinVec , MACRO_ARGUMENTS } ;
13
- use crate :: tokenstream:: { self , TokenStream , TokenTree } ;
13
+ use crate :: tokenstream:: { self , TokenStream } ;
14
14
use crate :: visit:: Visitor ;
15
15
16
16
use errors:: { DiagnosticBuilder , DiagnosticId } ;
@@ -235,18 +235,18 @@ pub trait TTMacroExpander {
235
235
}
236
236
237
237
pub type MacroExpanderFn =
238
- for <' cx > fn ( & ' cx mut ExtCtxt < ' _ > , Span , & [ tokenstream :: TokenTree ] )
238
+ for <' cx > fn ( & ' cx mut ExtCtxt < ' _ > , Span , TokenStream )
239
239
-> Box < dyn MacResult +' cx > ;
240
240
241
241
impl < F > TTMacroExpander for F
242
- where F : for < ' cx > Fn ( & ' cx mut ExtCtxt < ' _ > , Span , & [ tokenstream :: TokenTree ] )
242
+ where F : for < ' cx > Fn ( & ' cx mut ExtCtxt < ' _ > , Span , TokenStream )
243
243
-> Box < dyn MacResult +' cx >
244
244
{
245
245
fn expand < ' cx > (
246
246
& self ,
247
247
ecx : & ' cx mut ExtCtxt < ' _ > ,
248
248
span : Span ,
249
- input : TokenStream ,
249
+ mut input : TokenStream ,
250
250
) -> Box < dyn MacResult +' cx > {
251
251
struct AvoidInterpolatedIdents ;
252
252
@@ -268,10 +268,8 @@ impl<F> TTMacroExpander for F
268
268
mut_visit:: noop_visit_mac ( mac, self )
269
269
}
270
270
}
271
-
272
- let input: Vec < _ > =
273
- input. trees ( ) . map ( |mut tt| { AvoidInterpolatedIdents . visit_tt ( & mut tt) ; tt } ) . collect ( ) ;
274
- ( * self ) ( ecx, span, & input)
271
+ AvoidInterpolatedIdents . visit_tts ( & mut input) ;
272
+ ( * self ) ( ecx, span, input)
275
273
}
276
274
}
277
275
@@ -677,7 +675,7 @@ impl SyntaxExtension {
677
675
}
678
676
679
677
pub fn dummy_bang ( edition : Edition ) -> SyntaxExtension {
680
- fn expander < ' cx > ( _: & ' cx mut ExtCtxt < ' _ > , span : Span , _: & [ TokenTree ] )
678
+ fn expander < ' cx > ( _: & ' cx mut ExtCtxt < ' _ > , span : Span , _: TokenStream )
681
679
-> Box < dyn MacResult + ' cx > {
682
680
DummyResult :: any ( span)
683
681
}
@@ -811,9 +809,8 @@ impl<'a> ExtCtxt<'a> {
811
809
pub fn monotonic_expander < ' b > ( & ' b mut self ) -> expand:: MacroExpander < ' b , ' a > {
812
810
expand:: MacroExpander :: new ( self , true )
813
811
}
814
-
815
- pub fn new_parser_from_tts ( & self , tts : & [ tokenstream:: TokenTree ] ) -> parser:: Parser < ' a > {
816
- parse:: stream_to_parser ( self . parse_sess , tts. iter ( ) . cloned ( ) . collect ( ) , MACRO_ARGUMENTS )
812
+ pub fn new_parser_from_tts ( & self , stream : TokenStream ) -> parser:: Parser < ' a > {
813
+ parse:: stream_to_parser ( self . parse_sess , stream, MACRO_ARGUMENTS )
817
814
}
818
815
pub fn source_map ( & self ) -> & ' a SourceMap { self . parse_sess . source_map ( ) }
819
816
pub fn parse_sess ( & self ) -> & ' a parse:: ParseSess { self . parse_sess }
@@ -1019,7 +1016,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
1019
1016
/// done as rarely as possible).
1020
1017
pub fn check_zero_tts ( cx : & ExtCtxt < ' _ > ,
1021
1018
sp : Span ,
1022
- tts : & [ tokenstream :: TokenTree ] ,
1019
+ tts : TokenStream ,
1023
1020
name : & str ) {
1024
1021
if !tts. is_empty ( ) {
1025
1022
cx. span_err ( sp, & format ! ( "{} takes no arguments" , name) ) ;
@@ -1030,7 +1027,7 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>,
1030
1027
/// expect exactly one string literal, or emit an error and return `None`.
1031
1028
pub fn get_single_str_from_tts ( cx : & mut ExtCtxt < ' _ > ,
1032
1029
sp : Span ,
1033
- tts : & [ tokenstream :: TokenTree ] ,
1030
+ tts : TokenStream ,
1034
1031
name : & str )
1035
1032
-> Option < String > {
1036
1033
let mut p = cx. new_parser_from_tts ( tts) ;
@@ -1053,7 +1050,7 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt<'_>,
1053
1050
/// parsing error, emit a non-fatal error and return `None`.
1054
1051
pub fn get_exprs_from_tts ( cx : & mut ExtCtxt < ' _ > ,
1055
1052
sp : Span ,
1056
- tts : & [ tokenstream :: TokenTree ] ) -> Option < Vec < P < ast:: Expr > > > {
1053
+ tts : TokenStream ) -> Option < Vec < P < ast:: Expr > > > {
1057
1054
let mut p = cx. new_parser_from_tts ( tts) ;
1058
1055
let mut es = Vec :: new ( ) ;
1059
1056
while p. token != token:: Eof {
0 commit comments