@@ -785,13 +785,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
785785 issued_borrow : & BorrowData < ' tcx > ,
786786 explanation : BorrowExplanation ,
787787 ) {
788- let used_in_call =
789- matches ! ( explanation, BorrowExplanation :: UsedLater ( LaterUseKind :: Call , _call_span, _) ) ;
788+ let used_in_call = matches ! (
789+ explanation,
790+ BorrowExplanation :: UsedLater ( LaterUseKind :: Call | LaterUseKind :: Other , _call_span, _)
791+ ) ;
790792 if !used_in_call {
791793 debug ! ( "not later used in call" ) ;
792794 return ;
793795 }
794796
797+ let use_span =
798+ if let BorrowExplanation :: UsedLater ( LaterUseKind :: Other , use_span, _) = explanation {
799+ Some ( use_span)
800+ } else {
801+ None
802+ } ;
803+
795804 let outer_call_loc =
796805 if let TwoPhaseActivation :: ActivatedAt ( loc) = issued_borrow. activation_location {
797806 loc
@@ -835,7 +844,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
835844 debug ! ( "===> outer_call_loc = {:?}, inner_call_loc = {:?}" , outer_call_loc, inner_call_loc) ;
836845
837846 let inner_call_span = inner_call_term. source_info . span ;
838- let outer_call_span = outer_call_stmt. either ( |s| s. source_info , |t| t. source_info ) . span ;
847+ let outer_call_span = match use_span {
848+ Some ( span) => span,
849+ None => outer_call_stmt. either ( |s| s. source_info , |t| t. source_info ) . span ,
850+ } ;
839851 if outer_call_span == inner_call_span || !outer_call_span. contains ( inner_call_span) {
840852 // FIXME: This stops the suggestion in some cases where it should be emitted.
841853 // Fix the spans for those cases so it's emitted correctly.
@@ -845,8 +857,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
845857 ) ;
846858 return ;
847859 }
848- err. span_help ( inner_call_span, "try adding a local storing this argument..." ) ;
849- err. span_help ( outer_call_span, "...and then using that local as the argument to this call" ) ;
860+ err. span_help (
861+ inner_call_span,
862+ & format ! (
863+ "try adding a local storing this{}..." ,
864+ if use_span. is_some( ) { "" } else { " argument" }
865+ ) ,
866+ ) ;
867+ err. span_help (
868+ outer_call_span,
869+ & format ! (
870+ "...and then using that local {}" ,
871+ if use_span. is_some( ) { "here" } else { "as the argument to this call" }
872+ ) ,
873+ ) ;
850874 }
851875
852876 fn suggest_split_at_mut_if_applicable (
@@ -1912,10 +1936,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19121936 } else {
19131937 "cannot assign twice to immutable variable"
19141938 } ;
1915- if span != assigned_span {
1916- if !from_arg {
1917- err. span_label ( assigned_span, format ! ( "first assignment to {}" , place_description) ) ;
1918- }
1939+ if span != assigned_span && !from_arg {
1940+ err. span_label ( assigned_span, format ! ( "first assignment to {}" , place_description) ) ;
19191941 }
19201942 if let Some ( decl) = local_decl
19211943 && let Some ( name) = local_name
0 commit comments