@@ -362,16 +362,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
362
362
false
363
363
}
364
364
365
- fn replace_prefix < A , B , C > ( & self , s : A , old : B , new : C ) -> Option < String >
366
- where
367
- A : AsRef < str > ,
368
- B : AsRef < str > ,
369
- C : AsRef < str > ,
370
- {
371
- let s = s. as_ref ( ) ;
372
- let old = old. as_ref ( ) ;
365
+ fn replace_prefix ( & self , s : & str , old : & str , new : & str ) -> Option < String > {
373
366
if let Some ( stripped) = s. strip_prefix ( old) {
374
- Some ( new. as_ref ( ) . to_owned ( ) + stripped)
367
+ Some ( new. to_string ( ) + stripped)
375
368
} else {
376
369
None
377
370
}
@@ -422,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422
415
( & ty:: Str , & ty:: Array ( arr, _) | & ty:: Slice ( arr) ) if arr == self . tcx . types . u8 => {
423
416
if let hir:: ExprKind :: Lit ( _) = expr. kind {
424
417
if let Ok ( src) = sm. span_to_snippet ( sp) {
425
- if let Some ( src) = self . replace_prefix ( src, "b\" " , "\" " ) {
418
+ if let Some ( src) = self . replace_prefix ( & src, "b\" " , "\" " ) {
426
419
return Some ( (
427
420
sp,
428
421
"consider removing the leading `b`" ,
@@ -436,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
436
429
( & ty:: Array ( arr, _) | & ty:: Slice ( arr) , & ty:: Str ) if arr == self . tcx . types . u8 => {
437
430
if let hir:: ExprKind :: Lit ( _) = expr. kind {
438
431
if let Ok ( src) = sm. span_to_snippet ( sp) {
439
- if let Some ( src) = self . replace_prefix ( src, "\" " , "b\" " ) {
432
+ if let Some ( src) = self . replace_prefix ( & src, "\" " , "b\" " ) {
440
433
return Some ( (
441
434
sp,
442
435
"consider adding a leading `b`" ,
@@ -561,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
561
554
// we may want to suggest removing a `&`.
562
555
if sm. is_imported ( expr. span ) {
563
556
if let Ok ( src) = sm. span_to_snippet ( sp) {
564
- if let Some ( src) = self . replace_prefix ( src, "&" , "" ) {
557
+ if let Some ( src) = self . replace_prefix ( & src, "&" , "" ) {
565
558
return Some ( (
566
559
sp,
567
560
"consider removing the borrow" ,
@@ -598,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
598
591
match mutbl_a {
599
592
hir:: Mutability :: Mut => {
600
593
if let Some ( s) =
601
- self . replace_prefix ( src, "&mut " , new_prefix)
594
+ self . replace_prefix ( & src, "&mut " , & new_prefix)
602
595
{
603
596
Some ( ( s, Applicability :: MachineApplicable ) )
604
597
} else {
@@ -607,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
607
600
}
608
601
hir:: Mutability :: Not => {
609
602
if let Some ( s) =
610
- self . replace_prefix ( src, "&" , new_prefix)
603
+ self . replace_prefix ( & src, "&" , & new_prefix)
611
604
{
612
605
Some ( ( s, Applicability :: Unspecified ) )
613
606
} else {
@@ -621,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
621
614
match mutbl_a {
622
615
hir:: Mutability :: Mut => {
623
616
if let Some ( s) =
624
- self . replace_prefix ( src, "&mut " , new_prefix)
617
+ self . replace_prefix ( & src, "&mut " , & new_prefix)
625
618
{
626
619
Some ( ( s, Applicability :: MachineApplicable ) )
627
620
} else {
@@ -630,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630
623
}
631
624
hir:: Mutability :: Not => {
632
625
if let Some ( s) =
633
- self . replace_prefix ( src, "&" , new_prefix)
626
+ self . replace_prefix ( & src, "&" , & new_prefix)
634
627
{
635
628
Some ( ( s, Applicability :: MachineApplicable ) )
636
629
} else {
0 commit comments