blob: 9b0249bdc2a59fa84ee9a05e2b72a2651eb97ad0 [file] [log] [blame]
Alex Crichtond1985c92013-04-12 05:09:541// 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
17fn main() {
18 // negative cases
19 let mut a = 3; //~ ERROR: variable does not need to be mutable
Patrick Walton8114d0e2013-06-05 04:43:4120 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 Crichtond1985c92013-04-12 05:09:5422 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
35fn callback(f: &fn()) {}
36
37// make sure the lint attribute can be turned off
38#[allow(unused_mut)]
39fn foo(mut a: int) {
40 let mut a = 3;
41 let mut b = ~[2];
42}