Skip to content

Commit d5b6599

Browse files
committed
Add liveness test for unused_assignments for tricky lhs
1 parent a03222c commit d5b6599

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/test/compile-fail/liveness-unused.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#![deny(unused_assignments)]
1313
#![allow(dead_code, non_camel_case_types, trivial_numeric_casts)]
1414

15+
use std::ops::AddAssign;
16+
1517
fn f1(x: isize) {
1618
//~^ ERROR unused variable: `x`
1719
}
@@ -100,5 +102,30 @@ fn f5c() {
100102
}
101103
}
102104

105+
struct View<'a>(&'a mut [i32]);
106+
107+
impl<'a> AddAssign<i32> for View<'a> {
108+
fn add_assign(&mut self, rhs: i32) {
109+
for lhs in self.0.iter_mut() {
110+
*lhs += rhs;
111+
}
112+
}
113+
}
114+
115+
fn f6() {
116+
let mut array = [1, 2, 3];
117+
let mut v = View(&mut array);
118+
119+
// ensure an error shows up for x even if lhs of an overloaded add assign
120+
121+
let x;
122+
//~^ ERROR variable `x` is assigned to, but never used
123+
124+
*({
125+
x = 0; //~ ERROR value assigned to `x` is never read
126+
&mut v
127+
}) += 1;
128+
}
129+
103130
fn main() {
104131
}

0 commit comments

Comments
 (0)