@@ -685,80 +685,80 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
685
685
}
686
686
687
687
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
688
- fn token_kind_to_string ( & self , tok : & TokenKind ) -> String {
688
+ fn token_kind_to_string ( & self , tok : & TokenKind ) -> Cow < ' static , str > {
689
689
self . token_kind_to_string_ext ( tok, None )
690
690
}
691
691
692
692
fn token_kind_to_string_ext (
693
693
& self ,
694
694
tok : & TokenKind ,
695
695
convert_dollar_crate : Option < Span > ,
696
- ) -> String {
696
+ ) -> Cow < ' static , str > {
697
697
match * tok {
698
- token:: Eq => "=" . to_string ( ) ,
699
- token:: Lt => "<" . to_string ( ) ,
700
- token:: Le => "<=" . to_string ( ) ,
701
- token:: EqEq => "==" . to_string ( ) ,
702
- token:: Ne => "!=" . to_string ( ) ,
703
- token:: Ge => ">=" . to_string ( ) ,
704
- token:: Gt => ">" . to_string ( ) ,
705
- token:: Not => "!" . to_string ( ) ,
706
- token:: Tilde => "~" . to_string ( ) ,
707
- token:: OrOr => "||" . to_string ( ) ,
708
- token:: AndAnd => "&&" . to_string ( ) ,
709
- token:: BinOp ( op) => binop_to_string ( op) . to_string ( ) ,
710
- token:: BinOpEq ( op) => format ! ( "{}=" , binop_to_string( op) ) ,
698
+ token:: Eq => "=" . into ( ) ,
699
+ token:: Lt => "<" . into ( ) ,
700
+ token:: Le => "<=" . into ( ) ,
701
+ token:: EqEq => "==" . into ( ) ,
702
+ token:: Ne => "!=" . into ( ) ,
703
+ token:: Ge => ">=" . into ( ) ,
704
+ token:: Gt => ">" . into ( ) ,
705
+ token:: Not => "!" . into ( ) ,
706
+ token:: Tilde => "~" . into ( ) ,
707
+ token:: OrOr => "||" . into ( ) ,
708
+ token:: AndAnd => "&&" . into ( ) ,
709
+ token:: BinOp ( op) => binop_to_string ( op) . into ( ) ,
710
+ token:: BinOpEq ( op) => format ! ( "{}=" , binop_to_string( op) ) . into ( ) ,
711
711
712
712
/* Structural symbols */
713
- token:: At => "@" . to_string ( ) ,
714
- token:: Dot => "." . to_string ( ) ,
715
- token:: DotDot => ".." . to_string ( ) ,
716
- token:: DotDotDot => "..." . to_string ( ) ,
717
- token:: DotDotEq => "..=" . to_string ( ) ,
718
- token:: Comma => "," . to_string ( ) ,
719
- token:: Semi => ";" . to_string ( ) ,
720
- token:: Colon => ":" . to_string ( ) ,
721
- token:: ModSep => "::" . to_string ( ) ,
722
- token:: RArrow => "->" . to_string ( ) ,
723
- token:: LArrow => "<-" . to_string ( ) ,
724
- token:: FatArrow => "=>" . to_string ( ) ,
725
- token:: OpenDelim ( token:: Paren ) => "(" . to_string ( ) ,
726
- token:: CloseDelim ( token:: Paren ) => ")" . to_string ( ) ,
727
- token:: OpenDelim ( token:: Bracket ) => "[" . to_string ( ) ,
728
- token:: CloseDelim ( token:: Bracket ) => "]" . to_string ( ) ,
729
- token:: OpenDelim ( token:: Brace ) => "{" . to_string ( ) ,
730
- token:: CloseDelim ( token:: Brace ) => "}" . to_string ( ) ,
731
- token:: OpenDelim ( token:: NoDelim ) | token:: CloseDelim ( token:: NoDelim ) => "" . to_string ( ) ,
732
- token:: Pound => "#" . to_string ( ) ,
733
- token:: Dollar => "$" . to_string ( ) ,
734
- token:: Question => "?" . to_string ( ) ,
735
- token:: SingleQuote => "'" . to_string ( ) ,
713
+ token:: At => "@" . into ( ) ,
714
+ token:: Dot => "." . into ( ) ,
715
+ token:: DotDot => ".." . into ( ) ,
716
+ token:: DotDotDot => "..." . into ( ) ,
717
+ token:: DotDotEq => "..=" . into ( ) ,
718
+ token:: Comma => "," . into ( ) ,
719
+ token:: Semi => ";" . into ( ) ,
720
+ token:: Colon => ":" . into ( ) ,
721
+ token:: ModSep => "::" . into ( ) ,
722
+ token:: RArrow => "->" . into ( ) ,
723
+ token:: LArrow => "<-" . into ( ) ,
724
+ token:: FatArrow => "=>" . into ( ) ,
725
+ token:: OpenDelim ( token:: Paren ) => "(" . into ( ) ,
726
+ token:: CloseDelim ( token:: Paren ) => ")" . into ( ) ,
727
+ token:: OpenDelim ( token:: Bracket ) => "[" . into ( ) ,
728
+ token:: CloseDelim ( token:: Bracket ) => "]" . into ( ) ,
729
+ token:: OpenDelim ( token:: Brace ) => "{" . into ( ) ,
730
+ token:: CloseDelim ( token:: Brace ) => "}" . into ( ) ,
731
+ token:: OpenDelim ( token:: NoDelim ) | token:: CloseDelim ( token:: NoDelim ) => "" . into ( ) ,
732
+ token:: Pound => "#" . into ( ) ,
733
+ token:: Dollar => "$" . into ( ) ,
734
+ token:: Question => "?" . into ( ) ,
735
+ token:: SingleQuote => "'" . into ( ) ,
736
736
737
737
/* Literals */
738
- token:: Literal ( lit) => literal_to_string ( lit) ,
738
+ token:: Literal ( lit) => literal_to_string ( lit) . into ( ) ,
739
739
740
740
/* Name components */
741
741
token:: Ident ( s, is_raw) => {
742
- IdentPrinter :: new ( s, is_raw, convert_dollar_crate) . to_string ( )
742
+ IdentPrinter :: new ( s, is_raw, convert_dollar_crate) . to_string ( ) . into ( )
743
743
}
744
- token:: Lifetime ( s) => s. to_string ( ) ,
744
+ token:: Lifetime ( s) => s. to_string ( ) . into ( ) ,
745
745
746
746
/* Other */
747
747
token:: DocComment ( comment_kind, attr_style, data) => {
748
- doc_comment_to_string ( comment_kind, attr_style, data)
748
+ doc_comment_to_string ( comment_kind, attr_style, data) . into ( )
749
749
}
750
- token:: Eof => "<eof>" . to_string ( ) ,
750
+ token:: Eof => "<eof>" . into ( ) ,
751
751
752
- token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) ,
752
+ token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) . into ( ) ,
753
753
}
754
754
}
755
755
756
756
/// Print the token precisely, without converting `$crate` into its respective crate name.
757
- fn token_to_string ( & self , token : & Token ) -> String {
757
+ fn token_to_string ( & self , token : & Token ) -> Cow < ' static , str > {
758
758
self . token_to_string_ext ( token, false )
759
759
}
760
760
761
- fn token_to_string_ext ( & self , token : & Token , convert_dollar_crate : bool ) -> String {
761
+ fn token_to_string_ext ( & self , token : & Token , convert_dollar_crate : bool ) -> Cow < ' static , str > {
762
762
let convert_dollar_crate = convert_dollar_crate. then_some ( token. span ) ;
763
763
self . token_kind_to_string_ext ( & token. kind , convert_dollar_crate)
764
764
}
0 commit comments