1
1
pub ( crate ) mod printf {
2
+ use std:: borrow:: Cow ;
3
+
2
4
use rustc_span:: InnerSpan ;
3
5
4
6
use super :: strcursor:: StrCursor as Cur ;
@@ -13,10 +15,10 @@ pub(crate) mod printf {
13
15
}
14
16
15
17
impl < ' a > Substitution < ' a > {
16
- pub ( crate ) fn as_str ( & self ) -> & str {
18
+ pub ( crate ) fn as_string ( & self ) -> Cow < ' _ , str > {
17
19
match self {
18
- Substitution :: Format ( fmt) => fmt. span ,
19
- Substitution :: Escape ( _) => "%%" ,
20
+ Substitution :: Format ( fmt) => fmt. span . into ( ) ,
21
+ Substitution :: Escape ( _) => "%%" . into ( ) ,
20
22
}
21
23
}
22
24
@@ -616,6 +618,8 @@ pub(crate) mod printf {
616
618
}
617
619
618
620
pub ( crate ) mod shell {
621
+ use std:: borrow:: Cow ;
622
+
619
623
use rustc_span:: InnerSpan ;
620
624
621
625
use super :: strcursor:: StrCursor as Cur ;
@@ -628,10 +632,10 @@ pub(crate) mod shell {
628
632
}
629
633
630
634
impl Substitution < ' _ > {
631
- pub ( crate ) fn as_str ( & self ) -> String {
635
+ pub ( crate ) fn as_string ( & self ) -> Cow < ' _ , str > {
632
636
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 ( ) ,
635
639
Substitution :: Escape ( _) => "$$" . into ( ) ,
636
640
}
637
641
}
0 commit comments