11pub ( crate ) mod printf {
2+ use std:: borrow:: Cow ;
3+
24 use rustc_span:: InnerSpan ;
35
46 use super :: strcursor:: StrCursor as Cur ;
@@ -13,10 +15,10 @@ pub(crate) mod printf {
1315 }
1416
1517 impl < ' a > Substitution < ' a > {
16- pub ( crate ) fn as_str ( & self ) -> & str {
18+ pub ( crate ) fn as_string ( & self ) -> Cow < ' _ , str > {
1719 match self {
18- Substitution :: Format ( fmt) => fmt. span ,
19- Substitution :: Escape ( _) => "%%" ,
20+ Substitution :: Format ( fmt) => fmt. span . into ( ) ,
21+ Substitution :: Escape ( _) => "%%" . into ( ) ,
2022 }
2123 }
2224
@@ -616,6 +618,8 @@ pub(crate) mod printf {
616618}
617619
618620pub ( crate ) mod shell {
621+ use std:: borrow:: Cow ;
622+
619623 use rustc_span:: InnerSpan ;
620624
621625 use super :: strcursor:: StrCursor as Cur ;
@@ -628,10 +632,10 @@ pub(crate) mod shell {
628632 }
629633
630634 impl Substitution < ' _ > {
631- pub ( crate ) fn as_str ( & self ) -> String {
635+ pub ( crate ) fn as_string ( & self ) -> Cow < ' _ , str > {
632636 match self {
633- Substitution :: Ordinal ( n, _) => format ! ( "${n}" ) ,
634- Substitution :: Name ( n, _) => format ! ( "${n}" ) ,
637+ Substitution :: Ordinal ( n, _) => format ! ( "${n}" ) . into ( ) ,
638+ Substitution :: Name ( n, _) => format ! ( "${n}" ) . into ( ) ,
635639 Substitution :: Escape ( _) => "$$" . into ( ) ,
636640 }
637641 }
0 commit comments