Skip to content

Commit c9a9d24

Browse files
committed
---
yaml --- r: 146205 b: refs/heads/try2 c: f5e64ae h: refs/heads/master i: 146203: a585cb4 v: v3
1 parent f8b3039 commit c9a9d24

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 99b7662971e97cf53669b2f5620dcd9ff8b98bc3
8+
refs/heads/try2: f5e64aeb41ac1f567ba4261a66d4edb70b6a943f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/test/compile-fail/lint-unused-mut-variables.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ fn main() {
2020
let mut a = 2; //~ ERROR: variable does not need to be mutable
2121
let mut b = 3; //~ ERROR: variable does not need to be mutable
2222
let mut a = ~[3]; //~ ERROR: variable does not need to be mutable
23+
let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable
24+
25+
match 30 {
26+
mut x => {} //~ ERROR: variable does not need to be mutable
27+
}
28+
29+
let x = |mut y: int| 10; //~ ERROR: variable does not need to be mutable
30+
fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
2331

2432
// positive cases
2533
let mut a = 2;
@@ -30,6 +38,17 @@ fn main() {
3038
do callback {
3139
a.push(3);
3240
}
41+
let (mut a, b) = (1, 2);
42+
a = 34;
43+
44+
match 30 {
45+
mut x => {
46+
x = 21;
47+
}
48+
}
49+
50+
let x = |mut y: int| y = 32;
51+
fn nothing(mut foo: int) { foo = 37; }
3352
}
3453

3554
fn callback(f: &fn()) {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// Can't put mut in non-ident pattern
12+
13+
pub fn main() {
14+
struct Foo { x: int }
15+
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected `;` but found `{`
16+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
trait Foo {
12+
fn foo(&self, mut x: int) -> int {
13+
let val = x;
14+
x = 37 * x;
15+
val + x
16+
}
17+
}
18+
19+
struct X;
20+
impl Foo for X {}
21+
22+
pub fn main() {
23+
let (a, mut b) = (23, 4);
24+
assert_eq!(a, 23);
25+
assert_eq!(b, 4);
26+
b = a + b;
27+
assert_eq!(b, 27);
28+
29+
30+
assert_eq!(X.foo(2), 76);
31+
32+
enum Bar {
33+
Foo(int),
34+
Baz(f32, u8)
35+
}
36+
37+
let (x, mut y) = (32, Foo(21));
38+
39+
match x {
40+
mut z @ 32 => {
41+
assert_eq!(z, 32);
42+
z = 34;
43+
assert_eq!(z, 34);
44+
}
45+
_ => {}
46+
}
47+
48+
check_bar(&y);
49+
y = Baz(10.0, 3);
50+
check_bar(&y);
51+
52+
fn check_bar(y: &Bar) {
53+
match y {
54+
&Foo(a) => {
55+
assert_eq!(a, 21);
56+
}
57+
&Baz(a, b) => {
58+
assert_eq!(a, 10.0);
59+
assert_eq!(b, 3);
60+
}
61+
}
62+
}
63+
64+
fn foo1((x, mut y): (f64, int), mut z: int) -> int {
65+
y = 2 * 6;
66+
z = y + (x as int);
67+
y - z
68+
}
69+
70+
struct A {
71+
x: int
72+
}
73+
let A { x: mut x } = A { x: 10 };
74+
assert_eq!(x, 10);
75+
x = 30;
76+
assert_eq!(x, 30);
77+
78+
(|A { x: mut t }: A| { t = t+1; t })(A { x: 34 });
79+
80+
}

0 commit comments

Comments
 (0)