@@ -10,7 +10,7 @@ use crate::parse::token;
1010use crate :: ptr:: P ;
1111use crate :: symbol:: { kw, sym, Ident , Symbol } ;
1212use crate :: { ThinVec , MACRO_ARGUMENTS } ;
13- use crate :: tokenstream:: { self , TokenStream , TokenTree } ;
13+ use crate :: tokenstream:: { self , TokenStream } ;
1414use crate :: visit:: Visitor ;
1515
1616use errors:: { DiagnosticBuilder , DiagnosticId } ;
@@ -235,18 +235,18 @@ pub trait TTMacroExpander {
235235}
236236
237237pub type MacroExpanderFn =
238- for <' cx > fn ( & ' cx mut ExtCtxt < ' _ > , Span , & [ tokenstream :: TokenTree ] )
238+ for <' cx > fn ( & ' cx mut ExtCtxt < ' _ > , Span , TokenStream )
239239 -> Box < dyn MacResult +' cx > ;
240240
241241impl < 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 )
243243 -> Box < dyn MacResult +' cx >
244244{
245245 fn expand < ' cx > (
246246 & self ,
247247 ecx : & ' cx mut ExtCtxt < ' _ > ,
248248 span : Span ,
249- input : TokenStream ,
249+ mut input : TokenStream ,
250250 ) -> Box < dyn MacResult +' cx > {
251251 struct AvoidInterpolatedIdents ;
252252
@@ -268,10 +268,8 @@ impl<F> TTMacroExpander for F
268268 mut_visit:: noop_visit_mac ( mac, self )
269269 }
270270 }
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)
275273 }
276274}
277275
@@ -677,7 +675,7 @@ impl SyntaxExtension {
677675 }
678676
679677 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 )
681679 -> Box < dyn MacResult + ' cx > {
682680 DummyResult :: any ( span)
683681 }
@@ -811,9 +809,8 @@ impl<'a> ExtCtxt<'a> {
811809 pub fn monotonic_expander < ' b > ( & ' b mut self ) -> expand:: MacroExpander < ' b , ' a > {
812810 expand:: MacroExpander :: new ( self , true )
813811 }
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 )
817814 }
818815 pub fn source_map ( & self ) -> & ' a SourceMap { self . parse_sess . source_map ( ) }
819816 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)
10191016/// done as rarely as possible).
10201017pub fn check_zero_tts ( cx : & ExtCtxt < ' _ > ,
10211018 sp : Span ,
1022- tts : & [ tokenstream :: TokenTree ] ,
1019+ tts : TokenStream ,
10231020 name : & str ) {
10241021 if !tts. is_empty ( ) {
10251022 cx. span_err ( sp, & format ! ( "{} takes no arguments" , name) ) ;
@@ -1030,7 +1027,7 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>,
10301027/// expect exactly one string literal, or emit an error and return `None`.
10311028pub fn get_single_str_from_tts ( cx : & mut ExtCtxt < ' _ > ,
10321029 sp : Span ,
1033- tts : & [ tokenstream :: TokenTree ] ,
1030+ tts : TokenStream ,
10341031 name : & str )
10351032 -> Option < String > {
10361033 let mut p = cx. new_parser_from_tts ( tts) ;
@@ -1053,7 +1050,7 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt<'_>,
10531050/// parsing error, emit a non-fatal error and return `None`.
10541051pub fn get_exprs_from_tts ( cx : & mut ExtCtxt < ' _ > ,
10551052 sp : Span ,
1056- tts : & [ tokenstream :: TokenTree ] ) -> Option < Vec < P < ast:: Expr > > > {
1053+ tts : TokenStream ) -> Option < Vec < P < ast:: Expr > > > {
10571054 let mut p = cx. new_parser_from_tts ( tts) ;
10581055 let mut es = Vec :: new ( ) ;
10591056 while p. token != token:: Eof {
0 commit comments