@@ -9,6 +9,7 @@ use rustc_lint::LateContext;
99use rustc_middle:: hir:: nested_filter;
1010use rustc_middle:: ty:: { self , Ty } ;
1111use rustc_span:: symbol:: sym;
12+ use rustc_span:: Span ;
1213
1314pub ( super ) fn derefs_to_slice < ' tcx > (
1415 cx : & LateContext < ' tcx > ,
@@ -96,15 +97,15 @@ pub(super) fn clone_or_copy_needed<'tcx>(
9697 cx : & LateContext < ' tcx > ,
9798 pat : & Pat < ' tcx > ,
9899 body : & ' tcx Expr < ' tcx > ,
99- ) -> ( bool , Vec < & ' tcx Expr < ' tcx > > ) {
100+ ) -> ( bool , Vec < ( Span , String ) > ) {
100101 let mut visitor = CloneOrCopyVisitor {
101102 cx,
102103 binding_hir_ids : pat_bindings ( pat) ,
103104 clone_or_copy_needed : false ,
104- addr_of_exprs : Vec :: new ( ) ,
105+ references_to_binding : Vec :: new ( ) ,
105106 } ;
106107 visitor. visit_expr ( body) ;
107- ( visitor. clone_or_copy_needed , visitor. addr_of_exprs )
108+ ( visitor. clone_or_copy_needed , visitor. references_to_binding )
108109}
109110
110111/// Returns a vector of all `HirId`s bound by the pattern.
@@ -127,7 +128,7 @@ struct CloneOrCopyVisitor<'cx, 'tcx> {
127128 cx : & ' cx LateContext < ' tcx > ,
128129 binding_hir_ids : Vec < HirId > ,
129130 clone_or_copy_needed : bool ,
130- addr_of_exprs : Vec < & ' tcx Expr < ' tcx > > ,
131+ references_to_binding : Vec < ( Span , String ) > ,
131132}
132133
133134impl < ' cx , ' tcx > Visitor < ' tcx > for CloneOrCopyVisitor < ' cx , ' tcx > {
@@ -142,8 +143,11 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> {
142143 if self . is_binding ( expr) {
143144 if let Some ( parent) = get_parent_expr ( self . cx , expr) {
144145 match parent. kind {
145- ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , _) => {
146- self . addr_of_exprs . push ( parent) ;
146+ ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , referent) => {
147+ if !parent. span . from_expansion ( ) {
148+ self . references_to_binding
149+ . push ( ( parent. span . until ( referent. span ) , String :: new ( ) ) ) ;
150+ }
147151 return ;
148152 } ,
149153 ExprKind :: MethodCall ( .., args, _) => {
0 commit comments