1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 #![deny(unused_variables)]
13 #![deny(unused_assignments)]
14 #![allow(dead_code, non_camel_case_types, trivial_numeric_casts)]
16 use std::ops::AddAssign;
19 //~^ ERROR unused variable: `x`
22 fn f1b(x: &mut isize) {
23 //~^ ERROR unused variable: `x`
26 #[allow(unused_variables)]
31 //~^ ERROR unused variable: `x`
36 //~^ ERROR unused variable: `x`
41 //~^ ERROR variable `x` is assigned to, but never used
43 //~^ ERROR value assigned to `x` is never read
48 //~^ ERROR variable `z` is assigned to, but never used
54 #[allow(unused_variables)]
60 #[allow(unused_variables)]
61 #[allow(unused_assignments)]
70 //~^ ERROR unused variable: `i`
77 a(isize), b(isize), c(isize)
82 tri::a(i) | tri::b(i) | tri::c(i) => {
90 //~^ ERROR unused variable: `x`
94 for (x, _) in [1, 2, 3].iter().enumerate() { }
95 //~^ ERROR unused variable: `x`
99 for (_, x) in [1, 2, 3].iter().enumerate() {
100 //~^ ERROR unused variable: `x`
102 drop(*x as i32); //~ WARNING unreachable statement
106 struct View<'a>(&'a mut [i32]);
108 impl<'a> AddAssign<i32> for View<'a> {
109 fn add_assign(&mut self, rhs: i32) {
110 for lhs in self.0.iter_mut() {
117 let mut array = [1, 2, 3];
118 let mut v = View(&mut array);
120 // ensure an error shows up for x even if lhs of an overloaded add assign
123 //~^ ERROR variable `x` is assigned to, but never used
126 x = 0; //~ ERROR value assigned to `x` is never read
132 struct MutRef<'a>(&'a mut i32);
134 impl<'a> AddAssign<i32> for MutRef<'a> {
135 fn add_assign(&mut self, rhs: i32) {
143 // `b` does not trigger unused_variables
144 let mut b = MutRef(&mut a);