2017-07-27 04:51:09 +00:00
|
|
|
#![warn(unused)]
|
2014-10-27 22:37:07 +00:00
|
|
|
#![deny(unused_variables)]
|
|
|
|
#![deny(unused_assignments)]
|
2023-05-19 09:14:55 +00:00
|
|
|
#![allow(dead_code, non_camel_case_types, trivial_numeric_casts, dropping_copy_types)]
|
2013-04-09 17:16:27 +00:00
|
|
|
|
2016-03-04 20:44:45 +00:00
|
|
|
use std::ops::AddAssign;
|
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
fn f1(x: isize) {
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
fn f1b(x: &mut isize) {
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 22:37:07 +00:00
|
|
|
#[allow(unused_variables)]
|
2015-01-08 10:54:35 +00:00
|
|
|
fn f1c(x: isize) {}
|
2013-04-09 17:16:27 +00:00
|
|
|
|
2014-03-06 14:58:34 +00:00
|
|
|
fn f1d() {
|
2015-01-08 10:54:35 +00:00
|
|
|
let x: isize;
|
2014-03-06 14:58:34 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
|
|
|
}
|
|
|
|
|
2012-05-24 03:53:49 +00:00
|
|
|
fn f2() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let x = 3;
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn f3() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = 3;
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR variable `x` is assigned to, but never used
|
2015-01-31 16:23:42 +00:00
|
|
|
x += 4;
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR value assigned to `x` is never read
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn f3b() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut z = 3;
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR variable `z` is assigned to, but never used
|
2012-05-24 03:53:49 +00:00
|
|
|
loop {
|
2015-01-31 16:23:42 +00:00
|
|
|
z += 4;
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-27 22:37:07 +00:00
|
|
|
#[allow(unused_variables)]
|
2013-04-09 17:16:27 +00:00
|
|
|
fn f3c() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut z = 3;
|
|
|
|
loop { z += 4; }
|
2013-04-09 17:16:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 22:37:07 +00:00
|
|
|
#[allow(unused_variables)]
|
|
|
|
#[allow(unused_assignments)]
|
2013-04-09 17:16:27 +00:00
|
|
|
fn f3d() {
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = 3;
|
|
|
|
x += 4;
|
2013-04-09 17:16:27 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 03:53:49 +00:00
|
|
|
fn f4() {
|
2015-01-31 16:23:42 +00:00
|
|
|
match Some(3) {
|
2012-08-20 19:23:37 +00:00
|
|
|
Some(i) => {
|
2013-04-09 17:16:27 +00:00
|
|
|
//~^ ERROR unused variable: `i`
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
2012-08-20 19:23:37 +00:00
|
|
|
None => {}
|
2012-05-24 03:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 18:04:07 +00:00
|
|
|
enum tri {
|
2015-01-08 10:54:35 +00:00
|
|
|
a(isize), b(isize), c(isize)
|
2012-08-24 18:04:07 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
fn f4b() -> isize {
|
2015-01-31 16:23:42 +00:00
|
|
|
match tri::a(3) {
|
2014-11-06 08:05:53 +00:00
|
|
|
tri::a(i) | tri::b(i) | tri::c(i) => {
|
2012-08-24 18:04:07 +00:00
|
|
|
i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 20:07:00 +00:00
|
|
|
fn f5a() {
|
2015-01-31 16:23:42 +00:00
|
|
|
for x in 1..10 { }
|
2014-09-15 20:07:00 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f5b() {
|
2015-01-31 16:23:42 +00:00
|
|
|
for (x, _) in [1, 2, 3].iter().enumerate() { }
|
2014-09-15 20:07:00 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f5c() {
|
2015-01-31 16:23:42 +00:00
|
|
|
for (_, x) in [1, 2, 3].iter().enumerate() {
|
2014-09-15 20:07:00 +00:00
|
|
|
//~^ ERROR unused variable: `x`
|
|
|
|
continue;
|
2015-01-27 20:20:58 +00:00
|
|
|
drop(*x as i32); //~ WARNING unreachable statement
|
2014-09-15 20:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 20:44:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-04 21:52:34 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-05-24 03:53:49 +00:00
|
|
|
fn main() {
|
|
|
|
}
|