Skip to content

Commit

Permalink
Add liveness test for unused_assignments for tricky lhs
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Mar 4, 2016
1 parent a03222c commit d5b6599
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/compile-fail/liveness-unused.rs
Expand Up @@ -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`
}
Expand Down Expand Up @@ -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() {
}

0 comments on commit d5b6599

Please sign in to comment.