@@ -307,7 +307,7 @@ pub fn expr_block(
307
307
&& let ExprKind :: Block ( block, None ) = expr. kind
308
308
&& block. rules != BlockCheckMode :: UnsafeBlock ( UnsafeSource :: UserProvided )
309
309
{
310
- format ! ( "{ code}" )
310
+ code
311
311
} else {
312
312
// FIXME: add extra indent for the unsafe blocks:
313
313
// original code: unsafe { ... }
@@ -420,11 +420,10 @@ pub fn position_before_rarrow(s: &str) -> Option<usize> {
420
420
}
421
421
422
422
/// Reindent a multiline string with possibility of ignoring the first line.
423
- #[ expect( clippy:: needless_pass_by_value) ]
424
- pub fn reindent_multiline ( s : Cow < ' _ , str > , ignore_first : bool , indent : Option < usize > ) -> Cow < ' _ , str > {
425
- let s_space = reindent_multiline_inner ( & s, ignore_first, indent, ' ' ) ;
423
+ pub fn reindent_multiline ( s : & str , ignore_first : bool , indent : Option < usize > ) -> String {
424
+ let s_space = reindent_multiline_inner ( s, ignore_first, indent, ' ' ) ;
426
425
let s_tab = reindent_multiline_inner ( & s_space, ignore_first, indent, '\t' ) ;
427
- reindent_multiline_inner ( & s_tab, ignore_first, indent, ' ' ) . into ( )
426
+ reindent_multiline_inner ( & s_tab, ignore_first, indent, ' ' )
428
427
}
429
428
430
429
fn reindent_multiline_inner ( s : & str , ignore_first : bool , indent : Option < usize > , ch : char ) -> String {
@@ -552,42 +551,37 @@ pub fn snippet_opt(sess: &impl HasSession, span: Span) -> Option<String> {
552
551
/// } // aligned with `if`
553
552
/// ```
554
553
/// Note that the first line of the snippet always has 0 indentation.
555
- pub fn snippet_block < ' a > (
556
- sess : & impl HasSession ,
557
- span : Span ,
558
- default : & ' a str ,
559
- indent_relative_to : Option < Span > ,
560
- ) -> Cow < ' a , str > {
554
+ pub fn snippet_block ( sess : & impl HasSession , span : Span , default : & str , indent_relative_to : Option < Span > ) -> String {
561
555
let snip = snippet ( sess, span, default) ;
562
556
let indent = indent_relative_to. and_then ( |s| indent_of ( sess, s) ) ;
563
- reindent_multiline ( snip, true , indent)
557
+ reindent_multiline ( & snip, true , indent)
564
558
}
565
559
566
560
/// Same as `snippet_block`, but adapts the applicability level by the rules of
567
561
/// `snippet_with_applicability`.
568
- pub fn snippet_block_with_applicability < ' a > (
562
+ pub fn snippet_block_with_applicability (
569
563
sess : & impl HasSession ,
570
564
span : Span ,
571
- default : & ' a str ,
565
+ default : & str ,
572
566
indent_relative_to : Option < Span > ,
573
567
applicability : & mut Applicability ,
574
- ) -> Cow < ' a , str > {
568
+ ) -> String {
575
569
let snip = snippet_with_applicability ( sess, span, default, applicability) ;
576
570
let indent = indent_relative_to. and_then ( |s| indent_of ( sess, s) ) ;
577
- reindent_multiline ( snip, true , indent)
571
+ reindent_multiline ( & snip, true , indent)
578
572
}
579
573
580
- pub fn snippet_block_with_context < ' a > (
574
+ pub fn snippet_block_with_context (
581
575
sess : & impl HasSession ,
582
576
span : Span ,
583
577
outer : SyntaxContext ,
584
- default : & ' a str ,
578
+ default : & str ,
585
579
indent_relative_to : Option < Span > ,
586
580
app : & mut Applicability ,
587
- ) -> ( Cow < ' a , str > , bool ) {
581
+ ) -> ( String , bool ) {
588
582
let ( snip, from_macro) = snippet_with_context ( sess, span, outer, default, app) ;
589
583
let indent = indent_relative_to. and_then ( |s| indent_of ( sess, s) ) ;
590
- ( reindent_multiline ( snip, true , indent) , from_macro)
584
+ ( reindent_multiline ( & snip, true , indent) , from_macro)
591
585
}
592
586
593
587
/// Same as `snippet_with_applicability`, but first walks the span up to the given context.
@@ -748,11 +742,11 @@ mod test {
748
742
749
743
#[ test]
750
744
fn test_reindent_multiline_single_line ( ) {
751
- assert_eq ! ( "" , reindent_multiline( "" . into ( ) , false , None ) ) ;
752
- assert_eq ! ( "..." , reindent_multiline( "..." . into ( ) , false , None ) ) ;
753
- assert_eq ! ( "..." , reindent_multiline( " ..." . into ( ) , false , None ) ) ;
754
- assert_eq ! ( "..." , reindent_multiline( "\t ..." . into ( ) , false , None ) ) ;
755
- assert_eq ! ( "..." , reindent_multiline( "\t \t ..." . into ( ) , false , None ) ) ;
745
+ assert_eq ! ( "" , reindent_multiline( "" , false , None ) ) ;
746
+ assert_eq ! ( "..." , reindent_multiline( "..." , false , None ) ) ;
747
+ assert_eq ! ( "..." , reindent_multiline( " ..." , false , None ) ) ;
748
+ assert_eq ! ( "..." , reindent_multiline( "\t ..." , false , None ) ) ;
749
+ assert_eq ! ( "..." , reindent_multiline( "\t \t ..." , false , None ) ) ;
756
750
}
757
751
758
752
#[ test]
@@ -767,7 +761,7 @@ mod test {
767
761
y
768
762
} else {
769
763
z
770
- }" . into ( ) , false , None ) ) ;
764
+ }" , false , None ) ) ;
771
765
assert_eq ! ( "\
772
766
if x {
773
767
\t y
@@ -777,7 +771,7 @@ mod test {
777
771
\t y
778
772
} else {
779
773
\t z
780
- }" . into ( ) , false , None ) ) ;
774
+ }" , false , None ) ) ;
781
775
}
782
776
783
777
#[ test]
@@ -794,7 +788,7 @@ mod test {
794
788
795
789
} else {
796
790
z
797
- }" . into ( ) , false , None ) ) ;
791
+ }" , false , None ) ) ;
798
792
}
799
793
800
794
#[ test]
@@ -810,6 +804,6 @@ mod test {
810
804
y
811
805
} else {
812
806
z
813
- }" . into ( ) , true , Some ( 8 ) ) ) ;
807
+ }" , true , Some ( 8 ) ) ) ;
814
808
}
815
809
}
0 commit comments