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 // revisions: lexical nll
12 #![cfg_attr(nll, feature(nll))]
14 // Exercise the unused_mut attribute in some positive and negative cases
16 #![allow(unused_assignments)]
17 #![allow(unused_variables)]
24 let mut a = 3; //[lexical]~ ERROR: variable does not need to be mutable
25 //[nll]~^ ERROR: variable does not need to be mutable
26 let mut a = 2; //[lexical]~ ERROR: variable does not need to be mutable
27 //[nll]~^ ERROR: variable does not need to be mutable
28 let mut b = 3; //[lexical]~ ERROR: variable does not need to be mutable
29 //[nll]~^ ERROR: variable does not need to be mutable
30 let mut a = vec![3]; //[lexical]~ ERROR: variable does not need to be mutable
31 //[nll]~^ ERROR: variable does not need to be mutable
32 let (mut a, b) = (1, 2); //[lexical]~ ERROR: variable does not need to be mutable
33 //[nll]~^ ERROR: variable does not need to be mutable
34 let mut a; //[lexical]~ ERROR: variable does not need to be mutable
35 //[nll]~^ ERROR: variable does not need to be mutable
38 let mut b; //[lexical]~ ERROR: variable does not need to be mutable
39 //[nll]~^ ERROR: variable does not need to be mutable
47 mut x => {} //[lexical]~ ERROR: variable does not need to be mutable
48 //[nll]~^ ERROR: variable does not need to be mutable
51 (mut x, 1) | //[lexical]~ ERROR: variable does not need to be mutable
52 //[nll]~^ ERROR: variable does not need to be mutable
59 let x = |mut y: isize| 10; //[lexical]~ ERROR: variable does not need to be mutable
60 //[nll]~^ ERROR: variable does not need to be mutable
61 fn what(mut foo: isize) {} //[lexical]~ ERROR: variable does not need to be mutable
62 //[nll]~^ ERROR: variable does not need to be mutable
64 let mut a = &mut 5; //[lexical]~ ERROR: variable does not need to be mutable
65 //[nll]~^ ERROR: variable does not need to be mutable
69 let mut b = (&mut a,); //[lexical]~ ERROR: variable does not need to be mutable
70 *b.0 = 4; //[nll]~^ ERROR: variable does not need to be mutable
72 let mut x = &mut 1; //[lexical]~ ERROR: variable does not need to be mutable
73 //[nll]~^ ERROR: variable does not need to be mutable
79 fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
80 &mut arg[..] //[lexical]~^ ERROR: variable does not need to be mutable
81 //[nll]~^^ ERROR: variable does not need to be mutable
84 let mut v : &mut Vec<()> = &mut vec![]; //[lexical]~ ERROR: variable does not need to be mutable
85 //[nll]~^ ERROR: variable does not need to be mutable
91 let mut a = Vec::new();
93 let mut a = Vec::new();
97 let mut a = Vec::new();
103 let (mut a, b) = (1, 2);
121 let x = |mut y: isize| y = 32;
122 fn nothing(mut foo: isize) { foo = 37; }
124 // leading underscore should avoid the warning, just like the
125 // unused variable lint.
126 let mut _allowed = 1;
129 fn callback<F>(f: F) where F: FnOnce() {}
131 // make sure the lint attribute can be turned off
133 fn foo(mut a: isize) {
138 // make sure the lint attribute can be turned off on let statements
143 let mut b = vec![2]; //[lexical]~ ERROR: variable does not need to be mutable
144 //[nll]~^ ERROR: variable does not need to be mutable