@@ -360,10 +360,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
360
360
false
361
361
}
362
362
363
- fn replace_prefix ( & self , s : & str , old : & str , new : & str ) -> Option < String > {
364
- s. strip_prefix ( old) . map ( |stripped| new. to_string ( ) + stripped)
365
- }
366
-
367
363
/// This function is used to determine potential "simple" improvements or users' errors and
368
364
/// provide them useful help. For example:
369
365
///
@@ -394,6 +390,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394
390
return None ;
395
391
}
396
392
393
+ let replace_prefix = |s : & str , old : & str , new : & str | {
394
+ s. strip_prefix ( old) . map ( |stripped| new. to_string ( ) + stripped)
395
+ } ;
396
+
397
397
let is_struct_pat_shorthand_field =
398
398
self . is_hir_id_from_struct_pattern_shorthand_field ( expr. hir_id , sp) ;
399
399
@@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
409
409
( & ty:: Str , & ty:: Array ( arr, _) | & ty:: Slice ( arr) ) if arr == self . tcx . types . u8 => {
410
410
if let hir:: ExprKind :: Lit ( _) = expr. kind {
411
411
if let Ok ( src) = sm. span_to_snippet ( sp) {
412
- if let Some ( src) = self . replace_prefix ( & src, "b\" " , "\" " ) {
412
+ if let Some ( src) = replace_prefix ( & src, "b\" " , "\" " ) {
413
413
return Some ( (
414
414
sp,
415
415
"consider removing the leading `b`" ,
@@ -423,7 +423,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
423
423
( & ty:: Array ( arr, _) | & ty:: Slice ( arr) , & ty:: Str ) if arr == self . tcx . types . u8 => {
424
424
if let hir:: ExprKind :: Lit ( _) = expr. kind {
425
425
if let Ok ( src) = sm. span_to_snippet ( sp) {
426
- if let Some ( src) = self . replace_prefix ( & src, "\" " , "b\" " ) {
426
+ if let Some ( src) = replace_prefix ( & src, "\" " , "b\" " ) {
427
427
return Some ( (
428
428
sp,
429
429
"consider adding a leading `b`" ,
@@ -583,23 +583,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
583
583
hir:: Mutability :: Mut => {
584
584
let new_prefix = "&mut " . to_owned ( ) + derefs;
585
585
match mutbl_a {
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 ) ) ,
586
+ hir:: Mutability :: Mut => {
587
+ replace_prefix ( & src, "&mut " , & new_prefix)
588
+ . map ( |s| ( s, Applicability :: MachineApplicable ) )
589
+ }
590
+ hir:: Mutability :: Not => {
591
+ replace_prefix ( & src, "&" , & new_prefix)
592
+ . map ( |s| ( s, Applicability :: Unspecified ) )
593
+ }
592
594
}
593
595
}
594
596
hir:: Mutability :: Not => {
595
597
let new_prefix = "&" . to_owned ( ) + derefs;
596
598
match mutbl_a {
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 ) ) ,
599
+ hir:: Mutability :: Mut => {
600
+ replace_prefix ( & src, "&mut " , & new_prefix)
601
+ . map ( |s| ( s, Applicability :: MachineApplicable ) )
602
+ }
603
+ hir:: Mutability :: Not => {
604
+ replace_prefix ( & src, "&" , & new_prefix)
605
+ . map ( |s| ( s, Applicability :: MachineApplicable ) )
606
+ }
603
607
}
604
608
}
605
609
} {
0 commit comments