@@ -685,80 +685,80 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
685685 }
686686
687687 /// 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 > {
689689 self . token_kind_to_string_ext ( tok, None )
690690 }
691691
692692 fn token_kind_to_string_ext (
693693 & self ,
694694 tok : & TokenKind ,
695695 convert_dollar_crate : Option < Span > ,
696- ) -> String {
696+ ) -> Cow < ' static , str > {
697697 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 ( ) ,
711711
712712 /* 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 ( ) ,
736736
737737 /* Literals */
738- token:: Literal ( lit) => literal_to_string ( lit) ,
738+ token:: Literal ( lit) => literal_to_string ( lit) . into ( ) ,
739739
740740 /* Name components */
741741 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 ( )
743743 }
744- token:: Lifetime ( s) => s. to_string ( ) ,
744+ token:: Lifetime ( s) => s. to_string ( ) . into ( ) ,
745745
746746 /* Other */
747747 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 ( )
749749 }
750- token:: Eof => "<eof>" . to_string ( ) ,
750+ token:: Eof => "<eof>" . into ( ) ,
751751
752- token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) ,
752+ token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) . into ( ) ,
753753 }
754754 }
755755
756756 /// 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 > {
758758 self . token_to_string_ext ( token, false )
759759 }
760760
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 > {
762762 let convert_dollar_crate = convert_dollar_crate. then_some ( token. span ) ;
763763 self . token_kind_to_string_ext ( & token. kind , convert_dollar_crate)
764764 }
0 commit comments