]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-unused-mut-variables.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / test / compile-fail / lint-unused-mut-variables.rs
1 // Copyright 2013 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 // Exercise the unused_mut attribute in some positive and negative cases
12
13 #![allow(dead_assignment)]
14 #![allow(unused_variable)]
15 #![allow(dead_code)]
16 #![allow(deprecated_owned_vector)]
17 #![deny(unused_mut)]
18
19
20 fn main() {
21     // negative cases
22     let mut a = 3; //~ ERROR: variable does not need to be mutable
23     let mut a = 2; //~ ERROR: variable does not need to be mutable
24     let mut b = 3; //~ ERROR: variable does not need to be mutable
25     let mut a = vec!(3); //~ ERROR: variable does not need to be mutable
26     let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable
27
28     match 30 {
29         mut x => {} //~ ERROR: variable does not need to be mutable
30     }
31
32     let x = |mut y: int| 10; //~ ERROR: variable does not need to be mutable
33     fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
34
35     // positive cases
36     let mut a = 2;
37     a = 3;
38     let mut a = Vec::new();
39     a.push(3);
40     let mut a = Vec::new();
41     callback(|| {
42         a.push(3);
43     });
44     let (mut a, b) = (1, 2);
45     a = 34;
46
47     match 30 {
48         mut x => {
49             x = 21;
50         }
51     }
52
53     let x = |mut y: int| y = 32;
54     fn nothing(mut foo: int) { foo = 37; }
55
56     // leading underscore should avoid the warning, just like the
57     // unused variable lint.
58     let mut _allowed = 1;
59 }
60
61 fn callback(f: ||) {}
62
63 // make sure the lint attribute can be turned off
64 #[allow(unused_mut)]
65 fn foo(mut a: int) {
66     let mut a = 3;
67     let mut b = vec!(2);
68 }