]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/liveness-unused.rs
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.
11 #![deny(unused_variables)]
12 #![deny(unused_assignments)]
13 #![allow(dead_code, non_camel_case_types, trivial_numeric_casts)]
15 use std
::ops
::AddAssign
;
18 //~^ ERROR unused variable: `x`
21 fn f1b(x
: &mut isize) {
22 //~^ ERROR unused variable: `x`
25 #[allow(unused_variables)]
30 //~^ ERROR unused variable: `x`
35 //~^ ERROR unused variable: `x`
40 //~^ ERROR variable `x` is assigned to, but never used
42 //~^ ERROR value assigned to `x` is never read
47 //~^ ERROR variable `z` is assigned to, but never used
53 #[allow(unused_variables)]
59 #[allow(unused_variables)]
60 #[allow(unused_assignments)]
69 //~^ ERROR unused variable: `i`
76 a(isize), b(isize), c(isize)
81 tri
::a(i
) | tri
::b(i
) | tri
::c(i
) => {
89 //~^ ERROR unused variable: `x`
93 for (x
, _
) in [1, 2, 3].iter().enumerate() { }
94 //~^ ERROR unused variable: `x`
98 for (_
, x
) in [1, 2, 3].iter().enumerate() {
99 //~^ ERROR unused variable: `x`
101 drop(*x
as i32); //~ WARNING unreachable statement
105 struct View
<'a
>(&'a
mut [i32]);
107 impl<'a
> AddAssign
<i32> for View
<'a
> {
108 fn add_assign(&mut self, rhs
: i32) {
109 for lhs
in self.0.iter_mut
() {
116 let mut array
= [1, 2, 3];
117 let mut v
= View(&mut array
);
119 // ensure an error shows up for x even if lhs of an overloaded add assign
122 //~^ ERROR variable `x` is assigned to, but never used
125 x
= 0; //~ ERROR value assigned to `x` is never read
131 struct MutRef
<'a
>(&'a
mut i32);
133 impl<'a
> AddAssign
<i32> for MutRef
<'a
> {
134 fn add_assign(&mut self, rhs
: i32) {
142 // `b` does not trigger unused_variables
143 let mut b
= MutRef(&mut a
);