@@ -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:: Span ,
215
216
bridge:: client:: Group ,
216
- bridge:: client:: Punct ,
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:: Span ,
241
242
bridge:: client:: Group ,
242
- bridge:: client:: Punct ,
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:: Span ,
368
369
bridge:: client:: Group ,
369
- bridge:: client:: Punct ,
370
370
bridge:: client:: Ident ,
371
371
bridge:: client:: Literal ,
372
372
> ,
@@ -925,7 +925,7 @@ impl fmt::Debug for Group {
925
925
/// forms of `Spacing` returned.
926
926
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
927
927
#[ derive( Clone ) ]
928
- pub struct Punct ( bridge:: client:: Punct ) ;
928
+ pub struct Punct ( bridge:: Punct < bridge :: client:: Span > ) ;
929
929
930
930
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
931
931
impl !Send for Punct { }
@@ -958,13 +958,20 @@ impl Punct {
958
958
/// which can be further configured with the `set_span` method below.
959
959
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
960
960
pub fn new ( ch : char , spacing : Spacing ) -> Punct {
961
- Punct ( bridge:: client:: Punct :: new ( ch, spacing) )
961
+ const LEGAL_CHARS : & [ char ] = & [
962
+ '=' , '<' , '>' , '!' , '~' , '+' , '-' , '*' , '/' , '%' , '^' , '&' , '|' , '@' , '.' , ',' , ';' ,
963
+ ':' , '#' , '$' , '?' , '\'' ,
964
+ ] ;
965
+ if !LEGAL_CHARS . contains ( & ch) {
966
+ panic ! ( "unsupported character `{:?}`" , ch) ;
967
+ }
968
+ Punct ( bridge:: Punct { ch, joint : spacing == Spacing :: Joint , span : Span :: call_site ( ) . 0 } )
962
969
}
963
970
964
971
/// Returns the value of this punctuation character as `char`.
965
972
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
966
973
pub fn as_char ( & self ) -> char {
967
- self . 0 . as_char ( )
974
+ self . 0 . ch
968
975
}
969
976
970
977
/// Returns the spacing of this punctuation character, indicating whether it's immediately
@@ -973,28 +980,19 @@ impl Punct {
973
980
/// (`Alone`) so the operator has certainly ended.
974
981
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
975
982
pub fn spacing ( & self ) -> Spacing {
976
- self . 0 . spacing ( )
983
+ if self . 0 . joint { Spacing :: Joint } else { Spacing :: Alone }
977
984
}
978
985
979
986
/// Returns the span for this punctuation character.
980
987
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
981
988
pub fn span ( & self ) -> Span {
982
- Span ( self . 0 . span ( ) )
989
+ Span ( self . 0 . span )
983
990
}
984
991
985
992
/// Configure the span for this punctuation character.
986
993
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
987
994
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 ( )
995
+ self . 0 . span = span. 0 ;
998
996
}
999
997
}
1000
998
@@ -1003,7 +1001,7 @@ impl ToString for Punct {
1003
1001
#[ stable( feature = "proc_macro_lib2" , since = "1.29.0" ) ]
1004
1002
impl fmt:: Display for Punct {
1005
1003
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1006
- f . write_str ( & self . to_string ( ) )
1004
+ write ! ( f , "{}" , self . as_char ( ) )
1007
1005
}
1008
1006
}
1009
1007
0 commit comments