@@ -14,8 +14,8 @@ use rustc_span::def_id::CrateNum;
14
14
use rustc_span:: symbol:: { self , kw, sym, Symbol } ;
15
15
use rustc_span:: { BytePos , FileName , Pos , SourceFile , Span } ;
16
16
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 } ;
19
19
use std:: ops:: Bound ;
20
20
use std:: { ascii, panic} ;
21
21
@@ -50,7 +50,7 @@ impl ToInternal<token::Delimiter> for Delimiter {
50
50
}
51
51
52
52
impl FromInternal < ( TreeAndSpacing , & ' _ mut Vec < Self > , & mut Rustc < ' _ , ' _ > ) >
53
- for TokenTree < Group , Punct , Ident , Literal >
53
+ for TokenTree < Span , Group , Ident , Literal >
54
54
{
55
55
fn from_internal (
56
56
( ( tree, spacing) , stack, rustc) : ( TreeAndSpacing , & mut Vec < Self > , & mut Rustc < ' _ , ' _ > ) ,
@@ -79,16 +79,16 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
79
79
}
80
80
macro_rules! op {
81
81
( $a: expr) => {
82
- tt!( Punct :: new ( $a, joint) )
82
+ tt!( Punct { ch : $a, joint } )
83
83
} ;
84
84
( $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 } )
87
87
} } ;
88
88
( $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 } )
92
92
} } ;
93
93
}
94
94
@@ -146,7 +146,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
146
146
Lifetime ( name) => {
147
147
let ident = symbol:: Ident :: new ( name, span) . without_first_quote ( ) ;
148
148
stack. push ( tt ! ( Ident :: new( rustc. sess( ) , ident. name, false ) ) ) ;
149
- tt ! ( Punct :: new ( '\'' , true ) )
149
+ tt ! ( Punct { ch : '\'' , joint : true } )
150
150
}
151
151
Literal ( lit) => tt ! ( Literal { lit } ) ,
152
152
DocComment ( _, attr_style, data) => {
@@ -169,9 +169,9 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
169
169
flatten : false ,
170
170
} ) ) ;
171
171
if attr_style == ast:: AttrStyle :: Inner {
172
- stack. push ( tt ! ( Punct :: new ( '!' , false ) ) ) ;
172
+ stack. push ( tt ! ( Punct { ch : '!' , joint : false } ) ) ;
173
173
}
174
- tt ! ( Punct :: new ( '#' , false ) )
174
+ tt ! ( Punct { ch : '#' , joint : false } )
175
175
}
176
176
177
177
Interpolated ( nt) if let NtIdent ( ident, is_raw) = * nt => {
@@ -192,7 +192,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_, '_>)>
192
192
}
193
193
}
194
194
195
- impl ToInternal < TokenStream > for TokenTree < Group , Punct , Ident , Literal > {
195
+ impl ToInternal < TokenStream > for TokenTree < Span , Group , Ident , Literal > {
196
196
fn to_internal ( self ) -> TokenStream {
197
197
use rustc_ast:: token:: * ;
198
198
@@ -288,27 +288,6 @@ pub struct Group {
288
288
flatten : bool ,
289
289
}
290
290
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
-
312
291
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
313
292
pub struct Ident {
314
293
sym : Symbol ,
@@ -378,7 +357,6 @@ impl server::Types for Rustc<'_, '_> {
378
357
type FreeFunctions = FreeFunctions ;
379
358
type TokenStream = TokenStream ;
380
359
type Group = Group ;
381
- type Punct = Punct ;
382
360
type Ident = Ident ;
383
361
type Literal = Literal ;
384
362
type SourceFile = Lrc < SourceFile > ;
@@ -471,15 +449,15 @@ impl server::TokenStream for Rustc<'_, '_> {
471
449
472
450
fn from_token_tree (
473
451
& mut self ,
474
- tree : TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > ,
452
+ tree : TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > ,
475
453
) -> Self :: TokenStream {
476
454
tree. to_internal ( )
477
455
}
478
456
479
457
fn concat_trees (
480
458
& mut self ,
481
459
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 > > ,
483
461
) -> Self :: TokenStream {
484
462
let mut builder = tokenstream:: TokenStreamBuilder :: new ( ) ;
485
463
if let Some ( base) = base {
@@ -509,7 +487,7 @@ impl server::TokenStream for Rustc<'_, '_> {
509
487
fn into_trees (
510
488
& mut self ,
511
489
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 > > {
513
491
// FIXME: This is a raw port of the previous approach (which had a
514
492
// `TokenStreamIter` server-side object with a single `next` method),
515
493
// and can probably be optimized (for bulk conversion).
@@ -577,28 +555,6 @@ impl server::Group for Rustc<'_, '_> {
577
555
}
578
556
}
579
557
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
-
602
558
impl server:: Ident for Rustc < ' _ , ' _ > {
603
559
fn new ( & mut self , string : & str , span : Self :: Span , is_raw : bool ) -> Self :: Ident {
604
560
Ident :: new ( self . sess ( ) , Symbol :: intern ( string) , is_raw, span)
0 commit comments