]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/liveness-unused.rs
Convert most code to new inner attribute syntax.
[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_variable)]
12 #![deny(dead_assignment)]
13 #![allow(dead_code, non_camel_case_types)]
14
15 fn f1(x: int) {
16     //~^ ERROR unused variable: `x`
17 }
18
19 fn f1b(x: &mut int) {
20     //~^ ERROR unused variable: `x`
21 }
22
23 #[allow(unused_variable)]
24 fn f1c(x: int) {}
25
26 fn f1d() {
27     let x: int;
28     //~^ ERROR unused variable: `x`
29 }
30
31 fn f2() {
32     let x = 3;
33     //~^ ERROR unused variable: `x`
34 }
35
36 fn f3() {
37     let mut x = 3;
38     //~^ ERROR variable `x` is assigned to, but never used
39     x += 4;
40     //~^ ERROR value assigned to `x` is never read
41 }
42
43 fn f3b() {
44     let mut z = 3;
45     //~^ ERROR variable `z` is assigned to, but never used
46     loop {
47         z += 4;
48     }
49 }
50
51 #[allow(unused_variable)]
52 fn f3c() {
53     let mut z = 3;
54     loop { z += 4; }
55 }
56
57 #[allow(unused_variable)]
58 #[allow(dead_assignment)]
59 fn f3d() {
60     let mut x = 3;
61     x += 4;
62 }
63
64 fn f4() {
65     match Some(3) {
66       Some(i) => {
67         //~^ ERROR unused variable: `i`
68       }
69       None => {}
70     }
71 }
72
73 enum tri {
74     a(int), b(int), c(int)
75 }
76
77 fn f4b() -> int {
78     match a(3) {
79       a(i) | b(i) | c(i) => {
80         i
81       }
82     }
83 }
84
85 fn main() {
86 }