@@ -14,8 +14,8 @@ use rustc_span::def_id::CrateNum;
1414use rustc_span:: symbol:: { self , kw, sym, Symbol } ;
1515use rustc_span:: { BytePos , FileName , Pos , SourceFile , Span } ;
1616
17- use pm:: bridge:: { server, ExpnGlobals , TokenTree } ;
18- use pm:: { Delimiter , Level , LineColumn , Spacing } ;
17+ use pm:: bridge:: { server, ExpnGlobals , Punct , TokenTree } ;
18+ use pm:: { Delimiter , Level , LineColumn } ;
1919use std:: ops:: Bound ;
2020use std:: { ascii, panic} ;
2121
@@ -50,7 +50,7 @@ impl ToInternal<token::Delimiter> for Delimiter {
5050}
5151
5252impl FromInternal < ( TreeAndSpacing , & ' _ mut Vec < Self > , & mut Rustc < ' _ , ' _ > ) >
53- for TokenTree < Group , Punct , Ident , Literal >
53+ for TokenTree < Span , Group , Ident , Literal >
5454{
5555 fn from_internal (
5656 ( ( tree, spacing) , stack, rustc) : ( TreeAndSpacing , & mut Vec < Self > , & mut Rustc < ' _ , ' _ > ) ,
@@ -79,16 +79,16 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
7979 }
8080 macro_rules! op {
8181 ( $a: expr) => {
82- tt!( Punct :: new ( $a, joint) )
82+ tt!( Punct { ch : $a, joint } )
8383 } ;
8484 ( $a: expr, $b: expr) => { {
85- stack. push( tt!( Punct :: new ( $b, joint) ) ) ;
86- tt!( Punct :: new ( $a, true ) )
85+ stack. push( tt!( Punct { ch : $b, joint } ) ) ;
86+ tt!( Punct { ch : $a, joint : true } )
8787 } } ;
8888 ( $a: expr, $b: expr, $c: expr) => { {
89- stack. push( tt!( Punct :: new ( $c, joint) ) ) ;
90- stack. push( tt!( Punct :: new ( $b, true ) ) ) ;
91- tt!( Punct :: new ( $a, true ) )
89+ stack. push( tt!( Punct { ch : $c, joint } ) ) ;
90+ stack. push( tt!( Punct { ch : $b, joint : true } ) ) ;
91+ tt!( Punct { ch : $a, joint : true } )
9292 } } ;
9393 }
9494
@@ -146,7 +146,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
146146 Lifetime ( name) => {
147147 let ident = symbol:: Ident :: new ( name, span) . without_first_quote ( ) ;
148148 stack. push ( tt ! ( Ident :: new( rustc. sess( ) , ident. name, false ) ) ) ;
149- tt ! ( Punct :: new ( '\'' , true ) )
149+ tt ! ( Punct { ch : '\'' , joint : true } )
150150 }
151151 Literal ( lit) => tt ! ( Literal { lit } ) ,
152152 DocComment ( _, attr_style, data) => {
@@ -169,9 +169,9 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
169169 flatten : false ,
170170 } ) ) ;
171171 if attr_style == ast:: AttrStyle :: Inner {
172- stack. push ( tt ! ( Punct :: new ( '!' , false ) ) ) ;
172+ stack. push ( tt ! ( Punct { ch : '!' , joint : false } ) ) ;
173173 }
174- tt ! ( Punct :: new ( '#' , false ) )
174+ tt ! ( Punct { ch : '#' , joint : false } )
175175 }
176176
177177 Interpolated ( nt) if let NtIdent ( ident, is_raw) = * nt => {
@@ -192,7 +192,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
192192 }
193193}
194194
195- impl ToInternal < TokenStream > for TokenTree < Group , Punct , Ident , Literal > {
195+ impl ToInternal < TokenStream > for TokenTree < Span , Group , Ident , Literal > {
196196 fn to_internal ( self ) -> TokenStream {
197197 use rustc_ast:: token:: * ;
198198
@@ -288,27 +288,6 @@ pub struct Group {
288288 flatten : bool ,
289289}
290290
291- #[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
292- pub struct Punct {
293- ch : char ,
294- // NB. not using `Spacing` here because it doesn't implement `Hash`.
295- joint : bool ,
296- span : Span ,
297- }
298-
299- impl Punct {
300- fn new ( ch : char , joint : bool , span : Span ) -> Punct {
301- const LEGAL_CHARS : & [ char ] = & [
302- '=' , '<' , '>' , '!' , '~' , '+' , '-' , '*' , '/' , '%' , '^' , '&' , '|' , '@' , '.' , ',' , ';' ,
303- ':' , '#' , '$' , '?' , '\'' ,
304- ] ;
305- if !LEGAL_CHARS . contains ( & ch) {
306- panic ! ( "unsupported character `{:?}`" , ch)
307- }
308- Punct { ch, joint, span }
309- }
310- }
311-
312291#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
313292pub struct Ident {
314293 sym : Symbol ,
@@ -378,7 +357,6 @@ impl server::Types for Rustc<'_, '_> {
378357 type FreeFunctions = FreeFunctions ;
379358 type TokenStream = TokenStream ;
380359 type Group = Group ;
381- type Punct = Punct ;
382360 type Ident = Ident ;
383361 type Literal = Literal ;
384362 type SourceFile = Lrc < SourceFile > ;
@@ -471,15 +449,15 @@ impl server::TokenStream for Rustc<'_, '_> {
471449
472450 fn from_token_tree (
473451 & mut self ,
474- tree : TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > ,
452+ tree : TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > ,
475453 ) -> Self :: TokenStream {
476454 tree. to_internal ( )
477455 }
478456
479457 fn concat_trees (
480458 & mut self ,
481459 base : Option < Self :: TokenStream > ,
482- trees : Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > ,
460+ trees : Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > ,
483461 ) -> Self :: TokenStream {
484462 let mut builder = tokenstream:: TokenStreamBuilder :: new ( ) ;
485463 if let Some ( base) = base {
@@ -509,7 +487,7 @@ impl server::TokenStream for Rustc<'_, '_> {
509487 fn into_trees (
510488 & mut self ,
511489 stream : Self :: TokenStream ,
512- ) -> Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > {
490+ ) -> Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > {
513491 // FIXME: This is a raw port of the previous approach (which had a
514492 // `TokenStreamIter` server-side object with a single `next` method),
515493 // and can probably be optimized (for bulk conversion).
@@ -577,28 +555,6 @@ impl server::Group for Rustc<'_, '_> {
577555 }
578556}
579557
580- impl server:: Punct for Rustc < ' _ , ' _ > {
581- fn new ( & mut self , ch : char , spacing : Spacing ) -> Self :: Punct {
582- Punct :: new ( ch, spacing == Spacing :: Joint , self . call_site )
583- }
584-
585- fn as_char ( & mut self , punct : Self :: Punct ) -> char {
586- punct. ch
587- }
588-
589- fn spacing ( & mut self , punct : Self :: Punct ) -> Spacing {
590- if punct. joint { Spacing :: Joint } else { Spacing :: Alone }
591- }
592-
593- fn span ( & mut self , punct : Self :: Punct ) -> Self :: Span {
594- punct. span
595- }
596-
597- fn with_span ( & mut self , punct : Self :: Punct , span : Self :: Span ) -> Self :: Punct {
598- Punct { span, ..punct }
599- }
600- }
601-
602558impl server:: Ident for Rustc < ' _ , ' _ > {
603559 fn new ( & mut self , string : & str , span : Self :: Span , is_raw : bool ) -> Self :: Ident {
604560 Ident :: new ( self . sess ( ) , Symbol :: intern ( string) , is_raw, span)
0 commit comments