File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,15 @@ fn slice() {
46
46
foo. swap ( 0 , 1 ) ;
47
47
}
48
48
49
+ fn unswappable_slice ( ) {
50
+ let foo = & mut [ vec ! [ 1 , 2 ] , vec ! [ 3 , 4 ] ] ;
51
+ let temp = foo[ 0 ] [ 1 ] ;
52
+ foo[ 0 ] [ 1 ] = foo[ 1 ] [ 0 ] ;
53
+ foo[ 1 ] [ 0 ] = temp;
54
+
55
+ // swap(foo[0][1], foo[1][0]) would fail
56
+ }
57
+
49
58
fn vec ( ) {
50
59
let mut foo = vec ! [ 1 , 2 ] ;
51
60
let temp = foo[ 0 ] ;
Original file line number Diff line number Diff line change @@ -17,15 +17,15 @@ LL | | foo[1] = temp;
17
17
| |_________________^ help: try: `foo.swap(0, 1)`
18
18
19
19
error: this looks like you are swapping elements of `foo` manually
20
- --> $DIR/swap.rs:51 :5
20
+ --> $DIR/swap.rs:60 :5
21
21
|
22
22
LL | / let temp = foo[0];
23
23
LL | | foo[0] = foo[1];
24
24
LL | | foo[1] = temp;
25
25
| |_________________^ help: try: `foo.swap(0, 1)`
26
26
27
27
error: this looks like you are swapping `a` and `b` manually
28
- --> $DIR/swap.rs:71 :7
28
+ --> $DIR/swap.rs:80 :7
29
29
|
30
30
LL | ; let t = a;
31
31
| _______^
@@ -36,7 +36,7 @@ LL | | b = t;
36
36
= note: or maybe you should use `std::mem::replace`?
37
37
38
38
error: this looks like you are swapping `c.0` and `a` manually
39
- --> $DIR/swap.rs:80 :7
39
+ --> $DIR/swap.rs:89 :7
40
40
|
41
41
LL | ; let t = c.0;
42
42
| _______^
@@ -47,7 +47,7 @@ LL | | a = t;
47
47
= note: or maybe you should use `std::mem::replace`?
48
48
49
49
error: this looks like you are trying to swap `a` and `b`
50
- --> $DIR/swap.rs:68 :5
50
+ --> $DIR/swap.rs:77 :5
51
51
|
52
52
LL | / a = b;
53
53
LL | | b = a;
@@ -57,7 +57,7 @@ LL | | b = a;
57
57
= note: or maybe you should use `std::mem::replace`?
58
58
59
59
error: this looks like you are trying to swap `c.0` and `a`
60
- --> $DIR/swap.rs:77 :5
60
+ --> $DIR/swap.rs:86 :5
61
61
|
62
62
LL | / c.0 = a;
63
63
LL | | a = c.0;
You can’t perform that action at this time.
0 commit comments