@@ -658,80 +658,80 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
658
658
}
659
659
660
660
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
661
- fn token_kind_to_string ( & self , tok : & TokenKind ) -> String {
661
+ fn token_kind_to_string ( & self , tok : & TokenKind ) -> Cow < ' static , str > {
662
662
self . token_kind_to_string_ext ( tok, None )
663
663
}
664
664
665
665
fn token_kind_to_string_ext (
666
666
& self ,
667
667
tok : & TokenKind ,
668
668
convert_dollar_crate : Option < Span > ,
669
- ) -> String {
669
+ ) -> Cow < ' static , str > {
670
670
match * tok {
671
- token:: Eq => "=" . to_string ( ) ,
672
- token:: Lt => "<" . to_string ( ) ,
673
- token:: Le => "<=" . to_string ( ) ,
674
- token:: EqEq => "==" . to_string ( ) ,
675
- token:: Ne => "!=" . to_string ( ) ,
676
- token:: Ge => ">=" . to_string ( ) ,
677
- token:: Gt => ">" . to_string ( ) ,
678
- token:: Not => "!" . to_string ( ) ,
679
- token:: Tilde => "~" . to_string ( ) ,
680
- token:: OrOr => "||" . to_string ( ) ,
681
- token:: AndAnd => "&&" . to_string ( ) ,
682
- token:: BinOp ( op) => binop_to_string ( op) . to_string ( ) ,
683
- token:: BinOpEq ( op) => format ! ( "{}=" , binop_to_string( op) ) ,
671
+ token:: Eq => "=" . into ( ) ,
672
+ token:: Lt => "<" . into ( ) ,
673
+ token:: Le => "<=" . into ( ) ,
674
+ token:: EqEq => "==" . into ( ) ,
675
+ token:: Ne => "!=" . into ( ) ,
676
+ token:: Ge => ">=" . into ( ) ,
677
+ token:: Gt => ">" . into ( ) ,
678
+ token:: Not => "!" . into ( ) ,
679
+ token:: Tilde => "~" . into ( ) ,
680
+ token:: OrOr => "||" . into ( ) ,
681
+ token:: AndAnd => "&&" . into ( ) ,
682
+ token:: BinOp ( op) => binop_to_string ( op) . into ( ) ,
683
+ token:: BinOpEq ( op) => format ! ( "{}=" , binop_to_string( op) ) . into ( ) ,
684
684
685
685
/* Structural symbols */
686
- token:: At => "@" . to_string ( ) ,
687
- token:: Dot => "." . to_string ( ) ,
688
- token:: DotDot => ".." . to_string ( ) ,
689
- token:: DotDotDot => "..." . to_string ( ) ,
690
- token:: DotDotEq => "..=" . to_string ( ) ,
691
- token:: Comma => "," . to_string ( ) ,
692
- token:: Semi => ";" . to_string ( ) ,
693
- token:: Colon => ":" . to_string ( ) ,
694
- token:: ModSep => "::" . to_string ( ) ,
695
- token:: RArrow => "->" . to_string ( ) ,
696
- token:: LArrow => "<-" . to_string ( ) ,
697
- token:: FatArrow => "=>" . to_string ( ) ,
698
- token:: OpenDelim ( token:: Paren ) => "(" . to_string ( ) ,
699
- token:: CloseDelim ( token:: Paren ) => ")" . to_string ( ) ,
700
- token:: OpenDelim ( token:: Bracket ) => "[" . to_string ( ) ,
701
- token:: CloseDelim ( token:: Bracket ) => "]" . to_string ( ) ,
702
- token:: OpenDelim ( token:: Brace ) => "{" . to_string ( ) ,
703
- token:: CloseDelim ( token:: Brace ) => "}" . to_string ( ) ,
704
- token:: OpenDelim ( token:: NoDelim ) | token:: CloseDelim ( token:: NoDelim ) => "" . to_string ( ) ,
705
- token:: Pound => "#" . to_string ( ) ,
706
- token:: Dollar => "$" . to_string ( ) ,
707
- token:: Question => "?" . to_string ( ) ,
708
- token:: SingleQuote => "'" . to_string ( ) ,
686
+ token:: At => "@" . into ( ) ,
687
+ token:: Dot => "." . into ( ) ,
688
+ token:: DotDot => ".." . into ( ) ,
689
+ token:: DotDotDot => "..." . into ( ) ,
690
+ token:: DotDotEq => "..=" . into ( ) ,
691
+ token:: Comma => "," . into ( ) ,
692
+ token:: Semi => ";" . into ( ) ,
693
+ token:: Colon => ":" . into ( ) ,
694
+ token:: ModSep => "::" . into ( ) ,
695
+ token:: RArrow => "->" . into ( ) ,
696
+ token:: LArrow => "<-" . into ( ) ,
697
+ token:: FatArrow => "=>" . into ( ) ,
698
+ token:: OpenDelim ( token:: Paren ) => "(" . into ( ) ,
699
+ token:: CloseDelim ( token:: Paren ) => ")" . into ( ) ,
700
+ token:: OpenDelim ( token:: Bracket ) => "[" . into ( ) ,
701
+ token:: CloseDelim ( token:: Bracket ) => "]" . into ( ) ,
702
+ token:: OpenDelim ( token:: Brace ) => "{" . into ( ) ,
703
+ token:: CloseDelim ( token:: Brace ) => "}" . into ( ) ,
704
+ token:: OpenDelim ( token:: NoDelim ) | token:: CloseDelim ( token:: NoDelim ) => "" . into ( ) ,
705
+ token:: Pound => "#" . into ( ) ,
706
+ token:: Dollar => "$" . into ( ) ,
707
+ token:: Question => "?" . into ( ) ,
708
+ token:: SingleQuote => "'" . into ( ) ,
709
709
710
710
/* Literals */
711
- token:: Literal ( lit) => literal_to_string ( lit) ,
711
+ token:: Literal ( lit) => literal_to_string ( lit) . into ( ) ,
712
712
713
713
/* Name components */
714
714
token:: Ident ( s, is_raw) => {
715
- IdentPrinter :: new ( s, is_raw, convert_dollar_crate) . to_string ( )
715
+ IdentPrinter :: new ( s, is_raw, convert_dollar_crate) . to_string ( ) . into ( )
716
716
}
717
- token:: Lifetime ( s) => s. to_string ( ) ,
717
+ token:: Lifetime ( s) => s. to_string ( ) . into ( ) ,
718
718
719
719
/* Other */
720
720
token:: DocComment ( comment_kind, attr_style, data) => {
721
- doc_comment_to_string ( comment_kind, attr_style, data)
721
+ doc_comment_to_string ( comment_kind, attr_style, data) . into ( )
722
722
}
723
- token:: Eof => "<eof>" . to_string ( ) ,
723
+ token:: Eof => "<eof>" . into ( ) ,
724
724
725
- token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) ,
725
+ token:: Interpolated ( ref nt) => self . nonterminal_to_string ( nt) . into ( ) ,
726
726
}
727
727
}
728
728
729
729
/// Print the token precisely, without converting `$crate` into its respective crate name.
730
- fn token_to_string ( & self , token : & Token ) -> String {
730
+ fn token_to_string ( & self , token : & Token ) -> Cow < ' static , str > {
731
731
self . token_to_string_ext ( token, false )
732
732
}
733
733
734
- fn token_to_string_ext ( & self , token : & Token , convert_dollar_crate : bool ) -> String {
734
+ fn token_to_string_ext ( & self , token : & Token , convert_dollar_crate : bool ) -> Cow < ' static , str > {
735
735
let convert_dollar_crate = convert_dollar_crate. then_some ( token. span ) ;
736
736
self . token_kind_to_string_ext ( & token. kind , convert_dollar_crate)
737
737
}
0 commit comments