]>
git.proxmox.com Git - rustc.git/blob - 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.
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.
11 // Exercise the unused_mut attribute in some positive and negative cases
13 #![allow(unused_assignments)]
14 #![allow(unused_variables)]
21 let mut a
= 3; //~ ERROR: variable does not need to be mutable
22 let mut a
= 2; //~ ERROR: variable does not need to be mutable
23 let mut b
= 3; //~ ERROR: variable does not need to be mutable
24 let mut a
= vec
!(3); //~ ERROR: variable does not need to be mutable
25 let (mut a
, b
) = (1, 2); //~ ERROR: variable does not need to be mutable
26 let mut a
; //~ ERROR: variable does not need to be mutable
29 let mut b
; //~ ERROR: variable does not need to be mutable
37 mut x
=> {}
//~ ERROR: variable does not need to be mutable
40 (mut x
, 1) | //~ ERROR: variable does not need to be mutable
47 let x
= |mut y
: isize| 10; //~ ERROR: variable does not need to be mutable
48 fn what(mut foo
: isize) {}
//~ ERROR: variable does not need to be mutable
53 let mut a
= Vec
::new();
55 let mut a
= Vec
::new();
59 let (mut a
, b
) = (1, 2);
77 let x
= |mut y
: isize| y
= 32;
78 fn nothing(mut foo
: isize) { foo = 37; }
80 // leading underscore should avoid the warning, just like the
81 // unused variable lint.
85 fn callback
<F
>(f
: F
) where F
: FnOnce() {}
87 // make sure the lint attribute can be turned off
89 fn foo(mut a
: isize) {