Add liveness test for unused_assignments for tricky lhs
This commit is contained in:
parent
a03222c2b1
commit
d5b6599ab6
1 changed files with 27 additions and 0 deletions
|
@ -12,6 +12,8 @@
|
|||
#![deny(unused_assignments)]
|
||||
#![allow(dead_code, non_camel_case_types, trivial_numeric_casts)]
|
||||
|
||||
use std::ops::AddAssign;
|
||||
|
||||
fn f1(x: isize) {
|
||||
//~^ ERROR unused variable: `x`
|
||||
}
|
||||
|
@ -100,5 +102,30 @@ fn f5c() {
|
|||
}
|
||||
}
|
||||
|
||||
struct View<'a>(&'a mut [i32]);
|
||||
|
||||
impl<'a> AddAssign<i32> for View<'a> {
|
||||
fn add_assign(&mut self, rhs: i32) {
|
||||
for lhs in self.0.iter_mut() {
|
||||
*lhs += rhs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn f6() {
|
||||
let mut array = [1, 2, 3];
|
||||
let mut v = View(&mut array);
|
||||
|
||||
// ensure an error shows up for x even if lhs of an overloaded add assign
|
||||
|
||||
let x;
|
||||
//~^ ERROR variable `x` is assigned to, but never used
|
||||
|
||||
*({
|
||||
x = 0; //~ ERROR value assigned to `x` is never read
|
||||
&mut v
|
||||
}) += 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue