@@ -9,6 +9,7 @@ use rustc_lint::LateContext;
9
9
use rustc_middle:: hir:: nested_filter;
10
10
use rustc_middle:: ty:: { self , Ty } ;
11
11
use rustc_span:: symbol:: sym;
12
+ use rustc_span:: Span ;
12
13
13
14
pub ( super ) fn derefs_to_slice < ' tcx > (
14
15
cx : & LateContext < ' tcx > ,
@@ -96,15 +97,15 @@ pub(super) fn clone_or_copy_needed<'tcx>(
96
97
cx : & LateContext < ' tcx > ,
97
98
pat : & Pat < ' tcx > ,
98
99
body : & ' tcx Expr < ' tcx > ,
99
- ) -> ( bool , Vec < & ' tcx Expr < ' tcx > > ) {
100
+ ) -> ( bool , Vec < ( Span , String ) > ) {
100
101
let mut visitor = CloneOrCopyVisitor {
101
102
cx,
102
103
binding_hir_ids : pat_bindings ( pat) ,
103
104
clone_or_copy_needed : false ,
104
- addr_of_exprs : Vec :: new ( ) ,
105
+ references_to_binding : Vec :: new ( ) ,
105
106
} ;
106
107
visitor. visit_expr ( body) ;
107
- ( visitor. clone_or_copy_needed , visitor. addr_of_exprs )
108
+ ( visitor. clone_or_copy_needed , visitor. references_to_binding )
108
109
}
109
110
110
111
/// Returns a vector of all `HirId`s bound by the pattern.
@@ -127,7 +128,7 @@ struct CloneOrCopyVisitor<'cx, 'tcx> {
127
128
cx : & ' cx LateContext < ' tcx > ,
128
129
binding_hir_ids : Vec < HirId > ,
129
130
clone_or_copy_needed : bool ,
130
- addr_of_exprs : Vec < & ' tcx Expr < ' tcx > > ,
131
+ references_to_binding : Vec < ( Span , String ) > ,
131
132
}
132
133
133
134
impl < ' cx , ' tcx > Visitor < ' tcx > for CloneOrCopyVisitor < ' cx , ' tcx > {
@@ -142,8 +143,11 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> {
142
143
if self . is_binding ( expr) {
143
144
if let Some ( parent) = get_parent_expr ( self . cx , expr) {
144
145
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
+ }
147
151
return ;
148
152
} ,
149
153
ExprKind :: MethodCall ( .., args, _) => {
0 commit comments