Do not trigger unused_variables lint for variable modified through AddAssign
Visit an overloaded += like a method call and not like an assignment.
This commit is contained in:
parent
d5b6599ab6
commit
cfe4efd052
@ -1086,11 +1086,17 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
}
|
||||
|
||||
hir::ExprAssignOp(_, ref l, ref r) => {
|
||||
// see comment on lvalues in
|
||||
// propagate_through_lvalue_components()
|
||||
let succ = self.write_lvalue(&l, succ, ACC_WRITE|ACC_READ);
|
||||
let succ = self.propagate_through_expr(&r, succ);
|
||||
self.propagate_through_lvalue_components(&l, succ)
|
||||
// an overloaded assign op is like a method call
|
||||
if self.ir.tcx.is_method_call(expr.id) {
|
||||
let succ = self.propagate_through_expr(&l, succ);
|
||||
self.propagate_through_expr(&r, succ)
|
||||
} else {
|
||||
// see comment on lvalues in
|
||||
// propagate_through_lvalue_components()
|
||||
let succ = self.write_lvalue(&l, succ, ACC_WRITE|ACC_READ);
|
||||
let succ = self.propagate_through_expr(&r, succ);
|
||||
self.propagate_through_lvalue_components(&l, succ)
|
||||
}
|
||||
}
|
||||
|
||||
// Uninteresting cases: just propagate in rev exec order
|
||||
|
@ -127,5 +127,24 @@ fn f6() {
|
||||
}) += 1;
|
||||
}
|
||||
|
||||
|
||||
struct MutRef<'a>(&'a mut i32);
|
||||
|
||||
impl<'a> AddAssign<i32> for MutRef<'a> {
|
||||
fn add_assign(&mut self, rhs: i32) {
|
||||
*self.0 += rhs;
|
||||
}
|
||||
}
|
||||
|
||||
fn f7() {
|
||||
let mut a = 1;
|
||||
{
|
||||
// `b` does not trigger unused_variables
|
||||
let mut b = MutRef(&mut a);
|
||||
b += 1;
|
||||
}
|
||||
drop(a);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user