@@ -212,8 +212,8 @@ pub use quote::{quote, quote_span};
212
212
fn tree_to_bridge_tree (
213
213
tree : TokenTree ,
214
214
) -> bridge:: TokenTree <
215
- bridge:: client:: Group ,
216
- bridge:: client:: Punct ,
215
+ bridge:: client:: TokenStream ,
216
+ bridge:: client:: Span ,
217
217
bridge:: client:: Ident ,
218
218
bridge:: client:: Literal ,
219
219
> {
@@ -238,8 +238,8 @@ impl From<TokenTree> for TokenStream {
238
238
struct ConcatTreesHelper {
239
239
trees : Vec <
240
240
bridge:: TokenTree <
241
- bridge:: client:: Group ,
242
- bridge:: client:: Punct ,
241
+ bridge:: client:: TokenStream ,
242
+ bridge:: client:: Span ,
243
243
bridge:: client:: Ident ,
244
244
bridge:: client:: Literal ,
245
245
> ,
@@ -365,8 +365,8 @@ pub mod token_stream {
365
365
pub struct IntoIter (
366
366
std:: vec:: IntoIter <
367
367
bridge:: TokenTree <
368
- bridge:: client:: Group ,
369
- bridge:: client:: Punct ,
368
+ bridge:: client:: TokenStream ,
369
+ bridge:: client:: Span ,
370
370
bridge:: client:: Ident ,
371
371
bridge:: client:: Literal ,
372
372
> ,
@@ -788,7 +788,7 @@ impl fmt::Display for TokenTree {
788
788
/// A `Group` internally contains a `TokenStream` which is surrounded by `Delimiter`s.
789
789
#[ derive( Clone ) ]
790
790
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
791
- pub struct Group ( bridge:: client:: Group ) ;
791
+ pub struct Group ( bridge:: Group < bridge :: client:: TokenStream , bridge :: client :: Span > ) ;
792
792
793
793
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
794
794
impl !Send for Group { }
@@ -825,13 +825,17 @@ impl Group {
825
825
/// method below.
826
826
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
827
827
pub fn new ( delimiter : Delimiter , stream : TokenStream ) -> Group {
828
- Group ( bridge:: client:: Group :: new ( delimiter, stream. 0 ) )
828
+ Group ( bridge:: Group {
829
+ delimiter,
830
+ stream : stream. 0 ,
831
+ span : bridge:: DelimSpan :: from_single ( Span :: call_site ( ) . 0 ) ,
832
+ } )
829
833
}
830
834
831
835
/// Returns the delimiter of this `Group`
832
836
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
833
837
pub fn delimiter ( & self ) -> Delimiter {
834
- self . 0 . delimiter ( )
838
+ self . 0 . delimiter
835
839
}
836
840
837
841
/// Returns the `TokenStream` of tokens that are delimited in this `Group`.
@@ -840,7 +844,7 @@ impl Group {
840
844
/// returned above.
841
845
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
842
846
pub fn stream ( & self ) -> TokenStream {
843
- TokenStream ( Some ( self . 0 . stream ( ) ) )
847
+ TokenStream ( self . 0 . stream . clone ( ) )
844
848
}
845
849
846
850
/// Returns the span for the delimiters of this token stream, spanning the
@@ -852,7 +856,7 @@ impl Group {
852
856
/// ```
853
857
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
854
858
pub fn span ( & self ) -> Span {
855
- Span ( self . 0 . span ( ) )
859
+ Span ( self . 0 . span . entire )
856
860
}
857
861
858
862
/// Returns the span pointing to the opening delimiter of this group.
@@ -863,7 +867,7 @@ impl Group {
863
867
/// ```
864
868
#[ stable( feature = "proc_macro_group_span" , since = "1.55.0" ) ]
865
869
pub fn span_open ( & self ) -> Span {
866
- Span ( self . 0 . span_open ( ) )
870
+ Span ( self . 0 . span . open )
867
871
}
868
872
869
873
/// Returns the span pointing to the closing delimiter of this group.
@@ -874,7 +878,7 @@ impl Group {
874
878
/// ```
875
879
#[ stable( feature = "proc_macro_group_span" , since = "1.55.0" ) ]
876
880
pub fn span_close ( & self ) -> Span {
877
- Span ( self . 0 . span_close ( ) )
881
+ Span ( self . 0 . span . close )
878
882
}
879
883
880
884
/// Configures the span for this `Group`'s delimiters, but not its internal
@@ -885,7 +889,7 @@ impl Group {
885
889
/// tokens at the level of the `Group`.
886
890
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
887
891
pub fn set_span ( & mut self , span : Span ) {
888
- self . 0 . set_span ( span. 0 ) ;
892
+ self . 0 . span = bridge :: DelimSpan :: from_single ( span. 0 ) ;
889
893
}
890
894
}
891
895
@@ -925,7 +929,7 @@ impl fmt::Debug for Group {
925
929
/// forms of `Spacing` returned.
926
930
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
927
931
#[ derive( Clone ) ]
928
- pub struct Punct ( bridge:: client:: Punct ) ;
932
+ pub struct Punct ( bridge:: Punct < bridge :: client:: Span > ) ;
929
933
930
934
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
931
935
impl !Send for Punct { }
@@ -958,13 +962,24 @@ impl Punct {
958
962
/// which can be further configured with the `set_span` method below.
959
963
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
960
964
pub fn new ( ch : char , spacing : Spacing ) -> Punct {
961
- Punct ( bridge:: client:: Punct :: new ( ch, spacing) )
965
+ const LEGAL_CHARS : & [ char ] = & [
966
+ '=' , '<' , '>' , '!' , '~' , '+' , '-' , '*' , '/' , '%' , '^' , '&' , '|' , '@' , '.' , ',' , ';' ,
967
+ ':' , '#' , '$' , '?' , '\'' ,
968
+ ] ;
969
+ if !LEGAL_CHARS . contains ( & ch) {
970
+ panic ! ( "unsupported character `{:?}`" , ch) ;
971
+ }
972
+ Punct ( bridge:: Punct {
973
+ ch : ch as u8 ,
974
+ joint : spacing == Spacing :: Joint ,
975
+ span : Span :: call_site ( ) . 0 ,
976
+ } )
962
977
}
963
978
964
979
/// Returns the value of this punctuation character as `char`.
965
980
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
966
981
pub fn as_char ( & self ) -> char {
967
- self . 0 . as_char ( )
982
+ self . 0 . ch as char
968
983
}
969
984
970
985
/// Returns the spacing of this punctuation character, indicating whether it's immediately
@@ -973,28 +988,19 @@ impl Punct {
973
988
/// (`Alone`) so the operator has certainly ended.
974
989
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
975
990
pub fn spacing ( & self ) -> Spacing {
976
- self . 0 . spacing ( )
991
+ if self . 0 . joint { Spacing :: Joint } else { Spacing :: Alone }
977
992
}
978
993
979
994
/// Returns the span for this punctuation character.
980
995
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
981
996
pub fn span ( & self ) -> Span {
982
- Span ( self . 0 . span ( ) )
997
+ Span ( self . 0 . span )
983
998
}
984
999
985
1000
/// Configure the span for this punctuation character.
986
1001
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
987
1002
pub fn set_span ( & mut self , span : Span ) {
988
- self . 0 = self . 0 . with_span ( span. 0 ) ;
989
- }
990
- }
991
-
992
- // N.B., the bridge only provides `to_string`, implement `fmt::Display`
993
- // based on it (the reverse of the usual relationship between the two).
994
- #[ stable( feature = "proc_macro_lib" , since = "1.15.0" ) ]
995
- impl ToString for Punct {
996
- fn to_string ( & self ) -> String {
997
- TokenStream :: from ( TokenTree :: from ( self . clone ( ) ) ) . to_string ( )
1003
+ self . 0 . span = span. 0 ;
998
1004
}
999
1005
}
1000
1006
@@ -1003,7 +1009,7 @@ impl ToString for Punct {
1003
1009
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
1004
1010
impl fmt:: Display for Punct {
1005
1011
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1006
- f . write_str ( & self . to_string ( ) )
1012
+ write ! ( f , "{}" , self . as_char ( ) )
1007
1013
}
1008
1014
}
1009
1015
0 commit comments