@@ -19,8 +19,8 @@ use rustc_span::hygiene::ExpnKind;
19
19
use rustc_span:: symbol:: { self , kw, sym, Symbol } ;
20
20
use rustc_span:: { BytePos , FileName , MultiSpan , Pos , RealFileName , SourceFile , Span } ;
21
21
22
- use pm:: bridge:: { server, TokenTree } ;
23
- use pm:: { Delimiter , Level , LineColumn , Spacing } ;
22
+ use pm:: bridge:: { server, Punct , TokenTree } ;
23
+ use pm:: { Delimiter , Level , LineColumn } ;
24
24
use std:: ops:: Bound ;
25
25
use std:: { ascii, panic} ;
26
26
@@ -55,7 +55,7 @@ impl ToInternal<token::DelimToken> for Delimiter {
55
55
}
56
56
57
57
impl FromInternal < ( TreeAndSpacing , & ' _ mut Vec < Self > , & mut Rustc < ' _ > ) >
58
- for TokenTree < Group , Punct , Ident , Literal >
58
+ for TokenTree < Span , Group , Ident , Literal >
59
59
{
60
60
fn from_internal (
61
61
( ( tree, spacing) , stack, rustc) : ( TreeAndSpacing , & mut Vec < Self > , & mut Rustc < ' _ > ) ,
@@ -84,16 +84,16 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
84
84
}
85
85
macro_rules! op {
86
86
( $a: expr) => {
87
- tt!( Punct :: new ( $a, joint) )
87
+ tt!( Punct { ch : $a, joint } )
88
88
} ;
89
89
( $a: expr, $b: expr) => { {
90
- stack. push( tt!( Punct :: new ( $b, joint) ) ) ;
91
- tt!( Punct :: new ( $a, true ) )
90
+ stack. push( tt!( Punct { ch : $b, joint } ) ) ;
91
+ tt!( Punct { ch : $a, joint : true } )
92
92
} } ;
93
93
( $a: expr, $b: expr, $c: expr) => { {
94
- stack. push( tt!( Punct :: new ( $c, joint) ) ) ;
95
- stack. push( tt!( Punct :: new ( $b, true ) ) ) ;
96
- tt!( Punct :: new ( $a, true ) )
94
+ stack. push( tt!( Punct { ch : $c, joint } ) ) ;
95
+ stack. push( tt!( Punct { ch : $b, joint : true } ) ) ;
96
+ tt!( Punct { ch : $a, joint : true } )
97
97
} } ;
98
98
}
99
99
@@ -151,7 +151,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
151
151
Lifetime ( name) => {
152
152
let ident = symbol:: Ident :: new ( name, span) . without_first_quote ( ) ;
153
153
stack. push ( tt ! ( Ident :: new( rustc. sess, ident. name, false ) ) ) ;
154
- tt ! ( Punct :: new ( '\'' , true ) )
154
+ tt ! ( Punct { ch : '\'' , joint : true } )
155
155
}
156
156
Literal ( lit) => tt ! ( Literal { lit } ) ,
157
157
DocComment ( _, attr_style, data) => {
@@ -174,9 +174,9 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
174
174
flatten : false ,
175
175
} ) ) ;
176
176
if attr_style == ast:: AttrStyle :: Inner {
177
- stack. push ( tt ! ( Punct :: new ( '!' , false ) ) ) ;
177
+ stack. push ( tt ! ( Punct { ch : '!' , joint : false } ) ) ;
178
178
}
179
- tt ! ( Punct :: new ( '#' , false ) )
179
+ tt ! ( Punct { ch : '#' , joint : false } )
180
180
}
181
181
182
182
Interpolated ( nt) => {
@@ -199,7 +199,7 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
199
199
}
200
200
}
201
201
202
- impl ToInternal < TokenStream > for TokenTree < Group , Punct , Ident , Literal > {
202
+ impl ToInternal < TokenStream > for TokenTree < Span , Group , Ident , Literal > {
203
203
fn to_internal ( self ) -> TokenStream {
204
204
use rustc_ast:: token:: * ;
205
205
@@ -295,27 +295,6 @@ pub struct Group {
295
295
flatten : bool ,
296
296
}
297
297
298
- #[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
299
- pub struct Punct {
300
- ch : char ,
301
- // NB. not using `Spacing` here because it doesn't implement `Hash`.
302
- joint : bool ,
303
- span : Span ,
304
- }
305
-
306
- impl Punct {
307
- fn new ( ch : char , joint : bool , span : Span ) -> Punct {
308
- const LEGAL_CHARS : & [ char ] = & [
309
- '=' , '<' , '>' , '!' , '~' , '+' , '-' , '*' , '/' , '%' , '^' , '&' , '|' , '@' , '.' , ',' , ';' ,
310
- ':' , '#' , '$' , '?' , '\'' ,
311
- ] ;
312
- if !LEGAL_CHARS . contains ( & ch) {
313
- panic ! ( "unsupported character `{:?}`" , ch)
314
- }
315
- Punct { ch, joint, span }
316
- }
317
- }
318
-
319
298
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
320
299
pub struct Ident {
321
300
sym : Symbol ,
@@ -393,7 +372,6 @@ impl server::Types for Rustc<'_> {
393
372
type FreeFunctions = FreeFunctions ;
394
373
type TokenStream = TokenStream ;
395
374
type Group = Group ;
396
- type Punct = Punct ;
397
375
type Ident = Ident ;
398
376
type Literal = Literal ;
399
377
type SourceFile = Lrc < SourceFile > ;
@@ -425,14 +403,14 @@ impl server::TokenStream for Rustc<'_> {
425
403
}
426
404
fn from_token_tree (
427
405
& mut self ,
428
- tree : TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > ,
406
+ tree : TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > ,
429
407
) -> Self :: TokenStream {
430
408
tree. to_internal ( )
431
409
}
432
410
fn concat_trees (
433
411
& mut self ,
434
412
base : Option < Self :: TokenStream > ,
435
- trees : Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > ,
413
+ trees : Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > ,
436
414
) -> Self :: TokenStream {
437
415
let mut builder = tokenstream:: TokenStreamBuilder :: new ( ) ;
438
416
if let Some ( base) = base {
@@ -460,7 +438,7 @@ impl server::TokenStream for Rustc<'_> {
460
438
fn into_iter (
461
439
& mut self ,
462
440
stream : Self :: TokenStream ,
463
- ) -> Vec < TokenTree < Self :: Group , Self :: Punct , Self :: Ident , Self :: Literal > > {
441
+ ) -> Vec < TokenTree < Self :: Span , Self :: Group , Self :: Ident , Self :: Literal > > {
464
442
// XXX: This is a raw port of the previous approach, and can probably be
465
443
// optimized.
466
444
let mut cursor = stream. trees ( ) ;
@@ -521,28 +499,6 @@ impl server::Group for Rustc<'_> {
521
499
}
522
500
}
523
501
524
- impl server:: Punct for Rustc < ' _ > {
525
- fn new ( & mut self , ch : char , spacing : Spacing ) -> Self :: Punct {
526
- Punct :: new ( ch, spacing == Spacing :: Joint , server:: Context :: call_site ( self ) )
527
- }
528
- fn as_char ( & mut self , punct : Self :: Punct ) -> char {
529
- punct. ch
530
- }
531
- fn spacing ( & mut self , punct : Self :: Punct ) -> Spacing {
532
- if punct. joint {
533
- Spacing :: Joint
534
- } else {
535
- Spacing :: Alone
536
- }
537
- }
538
- fn span ( & mut self , punct : Self :: Punct ) -> Self :: Span {
539
- punct. span
540
- }
541
- fn with_span ( & mut self , punct : Self :: Punct , span : Self :: Span ) -> Self :: Punct {
542
- Punct { span, ..punct }
543
- }
544
- }
545
-
546
502
impl server:: Ident for Rustc < ' _ > {
547
503
fn new ( & mut self , string : & str , span : Self :: Span , is_raw : bool ) -> Self :: Ident {
548
504
Ident :: new ( self . sess , Symbol :: intern ( string) , is_raw, span)
0 commit comments