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