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() {
4646 foo. swap ( 0 , 1 ) ;
4747}
4848
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+
4958fn vec ( ) {
5059 let mut foo = vec ! [ 1 , 2 ] ;
5160 let temp = foo[ 0 ] ;
Original file line number Diff line number Diff line change @@ -17,15 +17,15 @@ LL | | foo[1] = temp;
1717 | |_________________^ help: try: `foo.swap(0, 1)`
1818
1919error: this looks like you are swapping elements of `foo` manually
20- --> $DIR/swap.rs:51 :5
20+ --> $DIR/swap.rs:60 :5
2121 |
2222LL | / let temp = foo[0];
2323LL | | foo[0] = foo[1];
2424LL | | foo[1] = temp;
2525 | |_________________^ help: try: `foo.swap(0, 1)`
2626
2727error: this looks like you are swapping `a` and `b` manually
28- --> $DIR/swap.rs:71 :7
28+ --> $DIR/swap.rs:80 :7
2929 |
3030LL | ; let t = a;
3131 | _______^
@@ -36,7 +36,7 @@ LL | | b = t;
3636 = note: or maybe you should use `std::mem::replace`?
3737
3838error: this looks like you are swapping `c.0` and `a` manually
39- --> $DIR/swap.rs:80 :7
39+ --> $DIR/swap.rs:89 :7
4040 |
4141LL | ; let t = c.0;
4242 | _______^
@@ -47,7 +47,7 @@ LL | | a = t;
4747 = note: or maybe you should use `std::mem::replace`?
4848
4949error: this looks like you are trying to swap `a` and `b`
50- --> $DIR/swap.rs:68 :5
50+ --> $DIR/swap.rs:77 :5
5151 |
5252LL | / a = b;
5353LL | | b = a;
@@ -57,7 +57,7 @@ LL | | b = a;
5757 = note: or maybe you should use `std::mem::replace`?
5858
5959error: this looks like you are trying to swap `c.0` and `a`
60- --> $DIR/swap.rs:77 :5
60+ --> $DIR/swap.rs:86 :5
6161 |
6262LL | / c.0 = a;
6363LL | | a = c.0;
You can’t perform that action at this time.
0 commit comments