@@ -785,13 +785,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
785
785
issued_borrow : & BorrowData < ' tcx > ,
786
786
explanation : BorrowExplanation ,
787
787
) {
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
+ ) ;
790
792
if !used_in_call {
791
793
debug ! ( "not later used in call" ) ;
792
794
return ;
793
795
}
794
796
797
+ let use_span =
798
+ if let BorrowExplanation :: UsedLater ( LaterUseKind :: Other , use_span, _) = explanation {
799
+ Some ( use_span)
800
+ } else {
801
+ None
802
+ } ;
803
+
795
804
let outer_call_loc =
796
805
if let TwoPhaseActivation :: ActivatedAt ( loc) = issued_borrow. activation_location {
797
806
loc
@@ -835,7 +844,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
835
844
debug ! ( "===> outer_call_loc = {:?}, inner_call_loc = {:?}" , outer_call_loc, inner_call_loc) ;
836
845
837
846
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
+ } ;
839
851
if outer_call_span == inner_call_span || !outer_call_span. contains ( inner_call_span) {
840
852
// FIXME: This stops the suggestion in some cases where it should be emitted.
841
853
// Fix the spans for those cases so it's emitted correctly.
@@ -845,8 +857,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
845
857
) ;
846
858
return ;
847
859
}
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
+ ) ;
850
874
}
851
875
852
876
fn suggest_split_at_mut_if_applicable (
@@ -1912,10 +1936,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1912
1936
} else {
1913
1937
"cannot assign twice to immutable variable"
1914
1938
} ;
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) ) ;
1919
1941
}
1920
1942
if let Some ( decl) = local_decl
1921
1943
&& let Some ( name) = local_name
0 commit comments