@@ -780,8 +780,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
780
780
} else {
781
781
LaterUseKind :: FakeLetRead
782
782
}
783
- } else if self . was_captured_by_trait_object ( borrow) {
784
- LaterUseKind :: TraitCapture
783
+ } else if let Some ( unsize_span) = self . was_captured_by_trait_object ( borrow) {
784
+ // We drilled down the span to the actual location of the unsize, rather
785
+ // than the location of the borrow.
786
+ return ( LaterUseKind :: TraitCapture , unsize_span, None ) ;
785
787
} else if location. statement_index == block. statements . len ( ) {
786
788
if let TerminatorKind :: Call { func, call_source : CallSource :: Normal , .. } =
787
789
& block. terminator ( ) . kind
@@ -818,7 +820,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
818
820
/// Checks if a borrowed value was captured by a trait object. We do this by
819
821
/// looking forward in the MIR from the reserve location and checking if we see
820
822
/// an unsized cast to a trait object on our data.
821
- fn was_captured_by_trait_object ( & self , borrow : & BorrowData < ' tcx > ) -> bool {
823
+ fn was_captured_by_trait_object ( & self , borrow : & BorrowData < ' tcx > ) -> Option < Span > {
822
824
// Start at the reserve location, find the place that we want to see cast to a trait object.
823
825
let location = borrow. reserve_location ;
824
826
let block = & self . body [ location. block ] ;
@@ -834,10 +836,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
834
836
if let Some ( local) = place. as_local ( ) {
835
837
local
836
838
} else {
837
- return false ;
839
+ return None ;
838
840
}
839
841
} else {
840
- return false ;
842
+ return None ;
841
843
} ;
842
844
843
845
debug ! ( "was_captured_by_trait: target={:?} queue={:?}" , target, queue) ;
@@ -884,7 +886,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
884
886
if from == target {
885
887
debug ! ( "was_captured_by_trait_object: ty={:?}" , ty) ;
886
888
// Check the type for a trait object.
887
- return match ty. kind ( ) {
889
+ let matches = match ty. kind ( ) {
888
890
// `&dyn Trait`
889
891
ty:: Ref ( _, ty, _) if ty. is_trait ( ) => true ,
890
892
// `Box<dyn Trait>`
@@ -897,11 +899,16 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
897
899
// Anything else.
898
900
_ => false ,
899
901
} ;
902
+ if matches {
903
+ return Some ( stmt. source_info . span ) ;
904
+ } else {
905
+ return None ;
906
+ }
900
907
}
901
908
}
902
- return false ;
909
+ return None ;
903
910
}
904
- _ => return false ,
911
+ _ => return None ,
905
912
}
906
913
}
907
914
_ => { }
@@ -925,7 +932,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
925
932
) ;
926
933
// Check if one of the arguments to this function is the target place.
927
934
let found_target = args. iter ( ) . any ( |arg| {
928
- if let Operand :: Move ( place) = arg. node {
935
+ if let Operand :: Move ( place) | Operand :: Copy ( place ) = arg. node {
929
936
if let Some ( potential) = place. as_local ( ) {
930
937
potential == target
931
938
} else {
@@ -949,6 +956,6 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
949
956
}
950
957
951
958
// We didn't find anything and ran out of locations to check.
952
- false
959
+ None
953
960
}
954
961
}
0 commit comments