]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/liveness-unused.rs
Update compile fail tests to use isize.
[rust.git] / 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.
4 //
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.
10
11 #![deny(unused_variables)]
12 #![deny(unused_assignments)]
13 #![allow(dead_code, non_camel_case_types)]
14
15 fn f1(x: isize) {
16     //~^ ERROR unused variable: `x`
17 }
18
19 fn f1b(x: &mut isize) {
20     //~^ ERROR unused variable: `x`
21 }
22
23 #[allow(unused_variables)]
24 fn f1c(x: isize) {}
25
26 fn f1d() {
27     let x: isize;
28     //~^ ERROR unused variable: `x`
29 }
30
31 fn f2() {
32     let x = 3i;
33     //~^ ERROR unused variable: `x`
34 }
35
36 fn f3() {
37     let mut x = 3i;
38     //~^ ERROR variable `x` is assigned to, but never used
39     x += 4i;
40     //~^ ERROR value assigned to `x` is never read
41 }
42
43 fn f3b() {
44     let mut z = 3i;
45     //~^ ERROR variable `z` is assigned to, but never used
46     loop {
47         z += 4i;
48     }
49 }
50
51 #[allow(unused_variables)]
52 fn f3c() {
53     let mut z = 3i;
54     loop { z += 4i; }
55 }
56
57 #[allow(unused_variables)]
58 #[allow(unused_assignments)]
59 fn f3d() {
60     let mut x = 3i;
61     x += 4i;
62 }
63
64 fn f4() {
65     match Some(3i) {
66       Some(i) => {
67         //~^ ERROR unused variable: `i`
68       }
69       None => {}
70     }
71 }
72
73 enum tri {
74     a(isize), b(isize), c(isize)
75 }
76
77 fn f4b() -> isize {
78     match tri::a(3i) {
79       tri::a(i) | tri::b(i) | tri::c(i) => {
80         i
81       }
82     }
83 }
84
85 fn f5a() {
86     for x in range(1i, 10) { }
87     //~^ ERROR unused variable: `x`
88 }
89
90 fn f5b() {
91     for (x, _) in [1i, 2, 3].iter().enumerate() { }
92     //~^ ERROR unused variable: `x`
93 }
94
95 fn f5c() {
96     for (_, x) in [1i, 2, 3].iter().enumerate() {
97     //~^ ERROR unused variable: `x`
98         continue;
99         std::os::set_exit_status(*x); //~ WARNING unreachable statement
100     }
101 }
102
103 fn main() {
104 }