Alex Crichton | d1985c9 | 2013-04-12 05:09:54 | [diff] [blame] | 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 | #[deny(unused_mut)]; |
| 16 | |
| 17 | fn main() { |
| 18 | // negative cases |
| 19 | let mut a = 3; //~ ERROR: variable does not need to be mutable |
Patrick Walton | 8114d0e | 2013-06-05 04:43:41 | [diff] [blame] | 20 | let mut a = 2; //~ ERROR: variable does not need to be mutable |
| 21 | let mut b = 3; //~ ERROR: variable does not need to be mutable |
Alex Crichton | d1985c9 | 2013-04-12 05:09:54 | [diff] [blame] | 22 | let mut a = ~[3]; //~ ERROR: variable does not need to be mutable |
| 23 | |
| 24 | // positive cases |
| 25 | let mut a = 2; |
| 26 | a = 3; |
| 27 | let mut a = ~[]; |
| 28 | a.push(3); |
| 29 | let mut a = ~[]; |
| 30 | do callback { |
| 31 | a.push(3); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | fn callback(f: &fn()) {} |
| 36 | |
| 37 | // make sure the lint attribute can be turned off |
| 38 | #[allow(unused_mut)] |
| 39 | fn foo(mut a: int) { |
| 40 | let mut a = 3; |
| 41 | let mut b = ~[2]; |
| 42 | } |