@@ -575,7 +575,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
575
575
// ---------- place
576
576
self . err . multipart_suggestions (
577
577
format ! (
578
- "use `.insert()` to insert a value into a `{}`, `.get_mut()` to modify it, or the entry API for more flexibility" ,
578
+ "use `.insert()` to insert a value into a `{}`, `.get_mut()` \
579
+ to modify it, or the entry API for more flexibility",
579
580
self . ty,
580
581
) ,
581
582
vec ! [
@@ -592,16 +593,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
592
593
( rv. span. shrink_to_hi( ) , ")" . to_string( ) ) ,
593
594
] ,
594
595
vec![
595
- // val.get_mut(index).map(|v| { *v = rv; });
596
+ // if let Some(v) = val.get_mut(index) { *v = rv; }
597
+ ( val. span. shrink_to_lo( ) , "if let Some(val) = " . to_string( ) ) ,
596
598
(
597
599
val. span. shrink_to_hi( ) . with_hi( index. span. lo( ) ) ,
598
600
".get_mut(" . to_string( ) ,
599
601
) ,
600
602
(
601
603
index. span. shrink_to_hi( ) . with_hi( place. span. hi( ) ) ,
602
- ").map(|val| { *val" . to_string( ) ,
604
+ ") { *val" . to_string( ) ,
603
605
) ,
604
- ( rv. span. shrink_to_hi( ) , "; }) " . to_string( ) ) ,
606
+ ( rv. span. shrink_to_hi( ) , "; }" . to_string( ) ) ,
605
607
] ,
606
608
vec![
607
609
// let x = val.entry(index).or_insert(rv);
@@ -628,15 +630,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628
630
self . err . multipart_suggestion (
629
631
format ! ( "to modify a `{}` use `.get_mut()`" , self . ty) ,
630
632
vec ! [
633
+ ( val. span. shrink_to_lo( ) , "if let Some(val) = " . to_string( ) ) ,
631
634
(
632
635
val. span. shrink_to_hi( ) . with_hi( index. span. lo( ) ) ,
633
636
".get_mut(" . to_string( ) ,
634
637
) ,
635
638
(
636
639
index. span. shrink_to_hi( ) . with_hi( receiver. span. hi( ) ) ,
637
- ").map(|val| val" . to_string( ) ,
640
+ ") { val" . to_string( ) ,
638
641
) ,
639
- ( sp. shrink_to_hi( ) , ")" . to_string( ) ) ,
642
+ ( sp. shrink_to_hi( ) , "); } " . to_string( ) ) ,
640
643
] ,
641
644
Applicability :: MachineApplicable ,
642
645
) ;
0 commit comments