@@ -361,11 +361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361
361
}
362
362
363
363
fn replace_prefix ( & self , s : & str , old : & str , new : & str ) -> Option < String > {
364
- if let Some ( stripped) = s. strip_prefix ( old) {
365
- Some ( new. to_string ( ) + stripped)
366
- } else {
367
- None
368
- }
364
+ s. strip_prefix ( old) . map ( |stripped| new. to_string ( ) + stripped)
369
365
}
370
366
371
367
/// This function is used to determine potential "simple" improvements or users' errors and
@@ -587,47 +583,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587
583
hir:: Mutability :: Mut => {
588
584
let new_prefix = "&mut " . to_owned ( ) + derefs;
589
585
match mutbl_a {
590
- hir:: Mutability :: Mut => {
591
- if let Some ( s) =
592
- self . replace_prefix ( & src, "&mut " , & new_prefix)
593
- {
594
- Some ( ( s, Applicability :: MachineApplicable ) )
595
- } else {
596
- None
597
- }
598
- }
599
- hir:: Mutability :: Not => {
600
- if let Some ( s) =
601
- self . replace_prefix ( & src, "&" , & new_prefix)
602
- {
603
- Some ( ( s, Applicability :: Unspecified ) )
604
- } else {
605
- None
606
- }
607
- }
586
+ hir:: Mutability :: Mut => self
587
+ . replace_prefix ( & src, "&mut " , & new_prefix)
588
+ . map ( |s| ( s, Applicability :: MachineApplicable ) ) ,
589
+ hir:: Mutability :: Not => self
590
+ . replace_prefix ( & src, "&" , & new_prefix)
591
+ . map ( |s| ( s, Applicability :: Unspecified ) ) ,
608
592
}
609
593
}
610
594
hir:: Mutability :: Not => {
611
595
let new_prefix = "&" . to_owned ( ) + derefs;
612
596
match mutbl_a {
613
- hir:: Mutability :: Mut => {
614
- if let Some ( s) =
615
- self . replace_prefix ( & src, "&mut " , & new_prefix)
616
- {
617
- Some ( ( s, Applicability :: MachineApplicable ) )
618
- } else {
619
- None
620
- }
621
- }
622
- hir:: Mutability :: Not => {
623
- if let Some ( s) =
624
- self . replace_prefix ( & src, "&" , & new_prefix)
625
- {
626
- Some ( ( s, Applicability :: MachineApplicable ) )
627
- } else {
628
- None
629
- }
630
- }
597
+ hir:: Mutability :: Mut => self
598
+ . replace_prefix ( & src, "&mut " , & new_prefix)
599
+ . map ( |s| ( s, Applicability :: MachineApplicable ) ) ,
600
+ hir:: Mutability :: Not => self
601
+ . replace_prefix ( & src, "&" , & new_prefix)
602
+ . map ( |s| ( s, Applicability :: MachineApplicable ) ) ,
631
603
}
632
604
}
633
605
} {
0 commit comments